[Closed] Using float number more than 10 digit
Hi everybody
If i need a number more than 10 digit like ( a = 0.12345678910 ) how should i do that ?
formattedPrint of the number will show more accurate number but it is in string and if i execute the string again it get back to normal number.
what you want exceeds the accuracy/precision for floats. And if I recall correctly, maxscript by default prints floats out to 6 decimal places… to go beyond that is pointless.
3DS Max does support double float precision since a long time ago. However, as soon as you do some “real” stuff, everything is
rounded to float.
But you can do your math using double values and then use the result to do some other stuff. It should be more precise than using float
values.
(
a = double 0.000000001
b = double 0.000000001
format "DOUBLE: %
%
" (a+b) (formattedprint (a+b) format:".10f")
a = float 0.000000001
b = float 0.000000001
format "FLOAT: %
%
" (a+b) (formattedprint (a+b) format:".10f")
)
Here is a better example of working with float and double values.
As you can see, cumulative errors are not minor and lead to very different results.
(
af = float 0.031565 -- 0.031565f
bf = float 0.015988 -- 0.015988f
cf = float 0.098796 -- 0.098796f
ad = af as double -- 0.031565d0
bd = bf as double -- 0.015988d0
cd = cf as double -- 0.098796d0
f = 0f
d = 0d0
for j = 1 to 10000 do
(
f += af + bf + cf
d += ad + bd + cd
)
clearlistener()
format "CORRECT RESULT: 1463.49
"
format " FLOAT: % <- WRONG
%
" (float f) (formattedprint f format:".10f")
format "DOUBLE: % <- CORRECT
%
" (float d) (formattedprint d format:".10f")
delete objects
box pos:[f,f,f] wirecolor:red -- Less accurate
box pos:[d,d,d] wirecolor:green -- More accurate
max zoomext sel all
)