Using float number more than 10 digit

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  10 October 2017
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.
  10 October 2017
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.
  10 October 2017
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

    a = double 0.000000001
    b = double 0.000000001
    format "DOUBLE: %\n%\n\n" (a+b) (formattedprint (a+b) format:".10f")
    a = float 0.000000001
    b = float 0.000000001
    format "FLOAT: %\n%\n\n" (a+b) (formattedprint (a+b) format:".10f")
Jorge Rodríguez
  10 October 2017
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
    format "CORRECT RESULT: 1463.49\n\n"
    format " FLOAT: %\t\t<- WRONG\n%\n\n"   (float f) (formattedprint f format:".10f")
    format "DOUBLE: %\t\t<- CORRECT\n%\n\n" (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
Jorge Rodríguez
reply share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:39 AM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.