Math Problem?

marathon332

Member
Licensed User
Longtime User
Erel:

Not sure if this is a bug or not but I'm using the code for TapeCalc in the contributions section and when I multiply 3 * 1.2 the answer I get is:

3.5999999999999996

instead of 3.6 which, of course, is the correct answer...

I tried it on multiples of 3 and it gives similar answers...

This code:

Result=Result*Val

does the math. The variables are both doubles which should be right...

Do you think it's an internal bug or am I doing something wrong?

--Steve
 

agraham

Expert
Licensed User
Longtime User
I haven't checked but I suspect the answer is in this sentence about Doubles in .NET

"By default, a Double value contains 15 decimal digits of precision, although a maximum of 17 digits is maintained internally."

I suspect that the default action of Double.ToString, which is what Basic4ppc uses to convert Doubles to Strings, does actually do a rounding from 17 to 15 digits. There is an option to get a "roundtrip" value that converts exactly to and from a string representation and I suspect this is not rounded and would show the effect.
 

jls890

Member
Licensed User
Longtime User
sin, cos and tan

Hi.
I am working in a RPN calculator, and I understand why
sin(3.141592653589793) gives a small number about 1E-16.
but don't understand why sinD(180) gives the same result.
The same happens for example sinD(130)=0.49999...4.
4? Why 4?

:signOops: Sorry for the up.
 
Top