StringToReal not accurate??
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/04/2005 at 20:53, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 9.102
Platform: Windows ;
Language(s) : C++ ;---------
Hello all, I'm trying to turn the C4D serial into a number.
I get the C4D serial just fine, but when I use StringToReal, I get the number, but just a little off.For example, I tried 12345678900 and ended up with 12345678848.
I've even tried setting up my own version of the StringToReal function and the same thing happens.
Tried in both 8.5 and 9.1.
Does C4D lose accuracy with numbers that large?
Has anyone experienced this before or know what's going on?
Is there a way around it?-Chris
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/04/2005 at 21:27, xxxxxxxx wrote:
Floating point values (on all computers) are approximations using a Mantissa and Exponent stored in 4 bytes (or 8 for double/long double). FP accuracy is not guaranteed past the number of Mantissa bits (I forget how many that is).
You should be treating the value as a long double real and use your own StringToDLong() to convert.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/04/2005 at 21:37, xxxxxxxx wrote:
Well I appreciate that info Robert. The StringToReal function I set up is pretty crude, so I guess I'll work on that. I'll be sure to post it if I get it in working order.
I noticed that I started to get the inaccuracies once the number got into the 100 millions.
Just for fun, I ported the code I was using to VB and it worked just fine, which suprised the hell out of me.
Oh well.
-Chris
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 26/04/2005 at 21:43, xxxxxxxx wrote:
VB is probably doing auto conversion to maintain appropriate storage. The double reals have 64-bits of mantissa which should be more than sufficient for accuracy in this situation - I hope! long double reals (Microsoft specific) has 80-bits of mantissa.