Maybe you answer is different from mine because you are running Perl in another architecture. Are you using a Intel based machine?
And how can I decide, up to what point I can trust Perl calculations?
Becasue it is a different situation that we have intrinsic error in floating point numbers like
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
For that kind of expected problems i am ready to check my values properly.
But for what I get from a call to a language function why should it be careful that it will return a wrong number?
Is there a way that I restrict Perl return values to what is safe for big number without truncating all return numbers from native Perl functions by myself?
And when Perl is returning numbers in this fashion can I be sure that if I use bigger numbers, the error wont grow to make more wrong digits?
| [reply] |
Maybe you answer is different from mine because you are running Perl in another architecture. Are you using a Intel based machine?
I've already said it's the underlying C library that makes the difference for cos().
And how can I decide, up to what point I can trust Perl calculations?
It's my understanding that libraries often approximate the result of trig functions. In Perl's case, it uses the underlying C library. I don't know what kind of precision guarantees (if any) C makes concerning its trig functions. Feel free to look it up.
And when Perl is returning numbers in this fashion can I be sure that if I use bigger numbers, the error wont grow to make more wrong digits?
I don't understand the question. You single out the previously discussed manner or returning numbers, but no ways of returning numbers were previously discussed. What does Perl returning numbers even mean? What are the other manners in which Perl returns numbers to which you allude?
Is there a way that I restrict Perl return values to what is safe for big number without truncating all return numbers from native Perl functions by myself?
The premise makes no sense. Truncating and rounding reduce precision.
Actual: -0.3633850893556905538...
Java's error: 0.0000000000000000538...
Your C's error: 0.0000000000001194462...
Rounded error: 0.0000000000003094462...
Truncated error: 0.0000000000006905538...
Besides that, the precision of the result of each operation depends on the precision of the result of each operand of that operation. Neither Perl nor the computer know the precision of the operands, so it can't know the precision of the output.
| [reply] [d/l] |
Maybe you answer is different from mine because you are running Perl in another architecture.
I am running perl in a different architecture (amd64), and I get the same result as you for perl:
C:\_32>perl -e "print cos(100000000.0)"
-0.36338508935581
I'm on Win32, and that's using the Microsoft C runtime library (msvcrt.dll). If I instead use the mpfr library, then I get the correct result:
C:\_32>perl -MMath::MPFR -e "$x=Math::MPFR->new(100000000.0);print cos
+($x)"
-3.6338508935569053e-1
Cheers, Rob | [reply] [d/l] [select] |