Notifications
Clear all

[Closed] Float: inner value vs display value????

This was what I was thinking of, not sure if it’ll help.
http://forums.cgsociety.org/showthread.php?t=683441

a = 11.047413 as float
11.0474
a *= 1000000 as integer
1.10474e+007
a as integer
11047413 OuR MAGiC MAx KNOW HOW TO DO WITH NUMBER [b]for amazing result

[/b]Uhm, I don’t understand what your “magic” problem is here, shouldn’t you use the following?

a = 11.047413 as float
11.0474
(a *= 1000000) as integer
11047413

well magic is

a = 34.047413 as float
34.0474
(a *= 1000000) as integer
34047412

Does it magical enough to you? :applause:

Thanks alot, Bobo thread point out the inaccurate of float as create weird number with just simple calculation (I dont know what algorithm used and so on 32 bit or else), but result is wrong and the fact I am facing to make them write down with right value that we could calculate even by hand.

The method of multiply with 1000000 seem broken now 🙁

I am thinking of another way, more critical, convert all input value to string, handle them to make into interger as string, and then convert back to number for calculation.

Remind me of DOS time, when we have many limitation of memory :wip:

Max provides Double, Integer64, and IntegerPtr.

You could potentially also use DotNet instead and use their numbers, such as Decimal, which may be better for what you are doing.

Generally I find Max is inconsistent or innacurate with lots of calculations, but be careful about whining or cursing about it on the forums- someone can come by with a real answer and suddenly you look like an idiot, or even worse, someone may be put off from answering you completely. Just a tip of advice.

Thanks

I tried with double before and It brings the same incorrect value like float.

About dotnet I dont think I could have time to grasp it.

They are not “random” and they are not “magic” numbers, as I said they are rounded numbers reached by the rounding scheme in single precision float.

You can’t multiply youself out of a rounding error because you’ll essentially make the error larger.

I’m not giving you any solutions as I don’t know those, I’m just pointing out the limitations.

Bobo … help…!

Please read HOW IT WORKS here:
http://en.wikipedia.org/wiki/Single_precision
and the main article here:
http://en.wikipedia.org/wiki/Floating_point

In short, MAXScript uses single precision floats unless you tell it to use doubles, and Maya uses double precision by default. But it is HOW COMPUTERS WORK with single precision floats, not how Max deals with them.

well thanks Bobo

But now I show you my 34 number case

a = 34.047413d0 as double
34.0474d0
formattedPrint a format:”.20g”
““34.047412999999999″”

So this mean even use double It may cause in-accurate calculation to my exporter :(… Do you have any ideas

Sorry double post

Page 2 / 3