check for decimal place
Hi, I'm looking to check if number == 1.86 or 3.45 for example.
I'm currently doing
if $i1 > 1. && $i1 < 2. then bang
however this doesn't seem to work, does anyone know of a way to check if a number has a decimal number?
You need to use $f1 for a floating point value. Note that Peter is going to write the next message, about precision of floating point numbers so called IEEE 754 ;-)
You might want to search that in the archive if you want to save one box ;)
Ha, as if i didn't realise that, such a school boy mistake. That's what I get for working at 2am on the night before a deadline!
Thanks
Emmanuel Jourdan wrote on Wed, 25 March 2009 03:00You need to use $f1 for a floating point value. Note that Peter is going to write the next message, about precision of floating point numbers so called IEEE 754
You might want to search that in the archive if you want to save one box
if peter shows up, ask him from me where i can find something like a complete list of maxpossible arguments to sprintf and expr.
You could use [route float int] to see if the input is decimal or not. This method can reports whole numbers as floats for example "1." rather than just "1". So you might want to try using [% 1] like in the example below.
lh
Roman Thilenius wrote on Wed, 25 March 2009 03:51
if peter shows up, ask him from me where i can find something like a complete list of maxpossible arguments to sprintf and expr.
Warum fragst Du mich nicht einfach selber, lieber Roman?
One of the side effects of the forum is that all my carefully crafted mail filters (more charmingly known as killfile entries) are for nought here.
To your question:
on Mac OS you can fire up Terminal and type 'man sprintf'
Alternately, try http://en.wikipedia.org/wiki/Sprintf
Alternately, any C programming reference. http://www.amazon.de/s/ref=nb_ss_w_0_11?__mk_de_DE=%C5M%C5Z%D5%D1&url=search-alias%3Daps&field-keywords=c+programmieren
Veuille accepter mes excuses, je te prie Emmanuel, pour ne pas réaliser tes prédictions selon lesquelles j'allasse faire référence au IEEE 754. Mais, on n'a pas besoin de cela en ce cas-ci .-)
weil ich für so etwas meine leute habe. das hab ich doch gar nicht nötig so etwas selbst zu machen.
thanks for the hint with the console, but bash does not reveal more about printf than it obviously have to do anything with "int".
i remebered that back in the days i looked on cplusplus.com and all i could find there was the use of i/d, f, and s - basicaly whats aleady described on the max helpfile.
so let me rephrase:
• is there any other interesting function of the max object beside those mentioned in the helpfile?
not long ago i found out about the 3 different "spaces" modes of (either tosymbol or strippath, have no max here now), which is really useful, and i dont want to miss something like that in printf ...
(this thread of officially hijacked now)
-110
Roman Thilenius wrote on Wed, 25 March 2009 16:21thanks for the hint with the console, but bash does not reveal more about printf than it obviously have to do anything with "int".
On Mac OS 10.5, man sprintf returns 21 screen pages of documentation. See attached.
Quote:is there any other interesting function of the max object beside those mentioned in the helpfile?
Note that there are thousands of implementations of sprintf in the world, they are not all identical, and there is no guarantee that the implementation embedded inside the Max sprintf object is identical to any other given implementation. The Mac OS and Windows implementations may even be different. I suspect the code is statically linked against whatever stdio library is provided by the XCode and VC IDEs (as always, Cycling '74 is good for a surprise on even the most plausible assumptions).
Try something. If it works, try it on the other platform. If it still works, hope it doesn't break on the next Max release. In short: caveat operator.
Returning to the original question...
ctb wrote on Wed, 25 March 2009 01:50
if $i1 > 1. && $i1 < 2. then bang
Aside from the $i/$f problem above, this is not the best way to check if a floating point input is actually an integer value.
The most general, reliable method is to coerce your float to an int, then compare that against the original value. Something like the following:
The checkbox is turned on iff the float had an integral value.
Peter Castine wrote on Thu, 26 March 2009 12:47
The checkbox is turned on iff the float had an integral value.
you see... I knew that you would eventually talk about IEEE 754
Emmanuel Jourdan wrote on Thu, 26 March 2009 17:10
you see... I knew that you would eventually talk about IEEE 754
Mais non ! Pas de tout !!
The technique I offered is far older than the standards of which you speak.
I will concede that the real thread running through my posts on floating point over the last 15 years is the following: if one wants to program arithmetic on a computer, one needs to understand how computers handle numbers. It's a little different from what we were taught in 2nd grade.
ctb wrote on Tue, 24 March 2009 20:16That's what I get for working at 2am on the night before a deadline!
All procrastinators will come to the point where they prefer the "woosh" sound when the deadline passes by over not going to bed...
Stefan