in reply to Re^3: Getting different results with $var++ and $var += 1
in thread Getting different results with $var++ and $var += 1
It's cheating because I've already got the answer (in part because you identified the problem) but this had nothing at all to do with the values being generated in the other objects. That I used Math::BigInt in the module (and didn't need it except for in one place) was the problem. So having arrived at the problem, the test case is pretty easy:
#!/usr/bin/perl use Math::BigInt ':constant'; $discount = 15; $price = "109.98"; print $discount * $price; exit();
Results NaN unless the use statement is commented out. Then it results in 1649.7;
I'm guessing the problem is that Math::BigInt is converting all numeric constants to Math::BigInt objects, without checking to see that the numeric constant is an integer or not. Since "109.98" is not an integer, Math::BigInt claims it isn't a number. I'm too ignorant to know whether that is by design or even whether that's really what's happening, but it is my guess.
|
|---|