why -1%4=3 in python 2.7? - math

Just starting out with Python, so this is probably my mistake, but...
I'm trying out Python. I like to use it as a calculator, and I'm slowly working through some tutorials.
I ran into something weird today. I wanted to find out -1%4, and got this:
>>> -1%4
3
I checked it on c and c++ compiles as well, and 3 is the wrong answer! -1 % 4 is supposed to be 3.
Why is Python giving me a wrong answer?

Related

Obtaining the QAST of a Perl 6 file from another program

This is related to this question on accesing the POD, but it goes further than that. You can easily access the Abstract Syntax Tree of a Perl 6 program using:
perl6 --target=ast -e '"Þor is mighty!".say'
This will print the whole Q abstract syntax tree. It's not too clear how to make this from your own program, or I haven't found how to do it. In fact, the CoreHackers::Q module runs that as an external script. But being able to access it from your own program, like
use QAST; # It does not exist
my $this-qast = QAST::Load("some-external-file.p6") # Would want something like this
would be great. I'm pretty sure it should be possible, at the NQP level and probably in a Rakudo-dependent way. Does someone know hot it goes?
Since QAST is not a part of the Perl 6 language specification, but an internal implementation detail of Rakudo, there's no official way to do this. Eventually there will be an AST form that is part of the language specification, but that doesn't yet exist (the 007 project which is working on exploring this area).
It is, however, possible to obtain the QAST tree by using:
use nqp;
my $ast = nqp::getcomp("perl6").eval("say 42", :target<ast>);
say $ast.dump();

#nloops macro in Julia 0.6

I'm reading the Base.Cartesian documentation of Julia language.
I've tried running examples provided there, for instance
#nloops 3 i A begin
s += #nref 3 A i
end
on my Julia 0.6 installation, but none of them works.
What am I doing wrong?
using Base.Cartesian
Credit to #Gnimuc in comments (idk why people doesn't answer instead of commenting)

Is there a length limitation of qDebug()<<?

In my code, I found one qDebug()<<s; didn't output the content given to it. It's very strange, so I output s.length(). It says 135254, so I'm wondering whether there is a limitation of length which is shorter than 135254? I have read the source header and do not find the result.
i noticed something similar...
This might narrow it down a bit (using Qt 5.5.1 with Windows mingw):
45000 character trace did not show up in qDebug.
10000 character trace did show up in qDebug.
I was able to qDebug my 45000 characters as 5 separate qDebug calls, each was something like this:
qDebug()<<foo.mid(20000, 10000);
then piece them together in a text editor.
it may have been a little nicer to use qDebug's noQuotes feature too, but i don't need to run my script again today so I'm not prettying it up right now.

Why does Julia> (1,2,3) return (1,2,0)

I've been working through the Julia Tutorial, and strangely (1,2,3) returns (1,2,0).
(1,2,3,4) returns (1,2,0,0)
(1,2,3,4,5) returns (1,2,3,4,5) as expected.
It seems that sets of size 3 or 4 replace the 3rd and fourth elements with 0. I don't expect that this is normal behavior but I'm not familiar with the environment so I'm not sure with what I might have done to cause this.
I deleted all julia files from my profile and restarted the interpreter, and the behavior persists.
Version 0.3.5 (2015-01-08 22:33 UTC) under windows executed in cygwin.
Same problem when executed from command.
This is a (very strange!) long standing display bug on Windows. You can read about it at the link - in short, the value is correct but it doesn't display right. It should also be fixed in final release of Julia 0.4, which will use LLVM 3.5 (at least, thats what the thread says).

OpenCV + Qt + cv::mat::deallocate and cv::fastFree(void *) memory problems

I've got two error messages:
cv::mat::deallocate
cv::fastFree(void *)
While I was trying to compile my OpenCV and QT project. I am fighting with this problem for fifth day. Please guys if you know how I can solve this problem, write it here.
PS: I've uploaded an image.
http://postimg.org/image/wsyq8daf5/
After this day, my problem with the camera was totally solved.There are no more problems.Now i will continue my GUI project thanks to all of you guys.After 1-2 months i will start searching for how to write printer driver ;), but however.Thanks too all again. ;)
Finally i solved my problem using the QCamera class.Well guys, use QCamera, you don't need anything else to capture videos or images.Read everything about it and bye bye ;)

Resources