### Calculation errors

When multiplying a value with a billion (for some reason I need to do that), The resulting value is not right. What is wrong and how can I solve it?

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 365.3ocqSFsaBBCEF95xSQSubgQn0Jws61ywhwTfiZMPKos5by369nEvoajL cStflS6Om9wGzCQHRtdOXI3mwuhQnCQHTXJ+Dn9ZDoVrunRXCwHKqzps0j3t kZDFQM3.yBPIxq.ejz90Zio25p.W3AY8ytTqbV4GgjTVxP3tjt2afNX76ivQ hwjbgZEAOuOmrLPgNeyizLxY8T0xQXoWLRQE4KFjpADnmf1UrVpVsv.Ettsi ynsnfmvy7CTtGLLKMIEO2+LGih72huRGof2ZAbfAGrOrKjGvzzgKxnRhdiRR pbiqF9MpF1uqF5L+vro+KyTCVqXE7C0PmlkvtONYbgL4tKD1rm7C7PgWNWHj .DjJo56mtBMzO+kVxp2ZJFdEFHFmd5coDrNoR3jZ04g3WDZsrrDTmeFrTZ8G KChHczuWWMO7qgmr+HOc5RzzrCL19dFPo82mMZiuLKNTJUckgNRLvN4Pddju aGi9Dz+kb3G -----------end_max5_patcher-----------

But still the value is not correct, this is the result: 156199993344.

Long story short, you can’t!

Integer values in Max (and most other programming languages and environments) have a quite limited range, about -2 billions to 2 billions. If you try to represent a value falling outside these boundaries, you’ll obtain some nonsense number.

Floating point values have a much wider range, but at some point you’ll fall outside of it and you’ll get an "infinite" value.

On the other hand, integers within their valid range are always exact; floats are always approximate, and the greater their absolute value, the worse the approximation… So, what you’re doing in your patch is multiplying some number fairly close to 156.2 for some other number fairly close to 10^9, and you’re getting a result fairly close to 1.562*10^11… if it makes any sense…

**all**of the following text. Then, in Max, select

*New From Clipboard*.

----------begin_max5_patcher---------- 560.3oc2WFsaaBCEF9Z3o.4KmxhvFigr61ywzTkSvM0UDCx1oKaU8ce3igtz 1sEGFhoRt.jsO7me94yGRdLNBss4jvfR9TxWRhhdLNJBlxMQT+3HzA9oc0bC TF515F0wCnU9kZ4Z9AgUnuQn3aqEtRR6Wq4nsVXseuU302cobKZUBZKWsGk7 095tsQYMxe.UgIqGt7VsvHTVtU1ntQK1Y8pPy1zURBKMycJs+vyh04Mop6qE LK9YWZ2cmTs+LYHvUlQHvIFHF4UB4uA.kH8yJqfPnY68er.cl+Uco.rxm0Rd MxsvSwwtCqBLWUhu0o5flVwIvnnOjfSG9rF82S1+sDMuH+xIJ4RIJYCERTb5 ERT7aSzxoMQ++SpLHWokS.oRXEilTyWNjpOQIoSAo5w9QQprkFoBvEsLeJH0 T5nI0rkCo5Sz7hIfTwErQSpzEYOUZHc.tHoh66.LFREuv5olsgLEjJF6NUt4 5AUx6TP85PtReLQIif3Xu6PtqCdxIikcvSbWtCBiguW7lrAmyVS9iYxDGGDn qDE1PgKup3HvWiBJhpkpW+O.AO4l+kYjo4nd2vca+OrL4W9pRXrREze4rZJe QM2IqpDpy29UIMtcjf6S+sOqB0MYA3F1r4lx.bSwr4FV.tIe1bCN.2PmO2DR 3PlM6PCvMYylaHA3F778nJj833YDcB4gEdrMc78m4ssOHzldMAqz81p6aztg rUvPoxODTDoEOHGpuL1o1Sw+DbOmWhE -----------end_max5_patcher-----------

sorry for the bad news!

aa

When multiplying a value with a billion (for some reason I need to do that)

It would be worth asking yourself if you **really** "need to do that". And how precise the result needs to be.

You’re banging your head against the limits of the IEEE 754 floating point specification. Which, incidentally, is more accurate floating point arithmetic than what was available when NASA put a man on the moon. Just for a point of perspective.

Your "incorrect" result of 156199993344 is off by the enormous «ahem» amount of 0.0004%. If you really higher accuracy, there are other ways of dealing with computer arithmetic to maintain greater precision, but most of them take a fair amount of work; the details depend on your needs. So, just what is that you’re doing that requires picometer accuracy?

Forums > MaxMSP