[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Re: Problems with "real" numbers
/x = 0.1 + 0.1 + 0.1
x == 0.3
-> false/
*The simplest is the best !*
/A general programming problem !
Equality checks with floats
have to be done with a defined threshold, e.g.
(x - 0.3).abs < 1e-4 // 1e-4 = 1 * (10 ** -4) = 0.0001
-> true/
*(x - 0.3).abs is the same as x - 0.3... In which way do you mean to use
what you show here ?*
/or use the dedicated method equalWithPrecision,
here with default threshold arg precision = 1e-4
x.equalWithPrecision(0.3)
-> true/
*Ok interesting method thanks, I might replace my choice with this but it's
a little tricky because of the need to define a degree of precision...so
I've got to think about it, anyway very good to know (gives me the idea to
explore a little more the SimpleNumber class) !
Cheers
T*
--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Problems-with-real-numbers-tp7622364p7622367.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/