Convert whole-number float to int
Hi folks,
I'm a long-time Max/MSP user, but first-time poster to the forum. I've always been able to find my answers by just searching the manuals or here, until now.
I am looking for a way to separate whole-number floats (ex. 2.0, 5.0, 12.0, etc.) from non-whole-number floats (1.3, 2.33333, 6.25, etc.) so that I can convert the whole-number floats to ints. Any ideas or suggestions will be greatly appreciated. Thanks.
-Brian
Can you use the modulo operator (%) to test for floats without
fractional amounts by dividing them by their integer portion and testing
for > 0?
On 3/12/07 1:25 PM, Brian Shepard wrote:
> Hi folks,
>
> I'm a long-time Max/MSP user, but first-time poster to the forum. I've always been able to find my answers by just searching the manuals or here, until now.
>
> I am looking for a way to separate whole-number floats (ex. 2.0, 5.0, 12.0, etc.) from non-whole-number floats (1.3, 2.33333, 6.25, etc.) so that I can convert the whole-number floats to ints. Any ideas or suggestions will be greatly appreciated. Thanks.
>
> -Brian
>
I should clarify that I want to keep the non-whole-number floats as floats and only convert the whole-number ones.
-Brian
Julien,
That works fabulously, thank you!
I would really like to see what was once written in these blank posts...
i can only guess.
[if int($f1)==$f1 then $f1 else out2 $f1]
then do the type conversion for the whole numbers.
-110
Ah ha... I didn't yet know that there were functions that could be used in 'if' and '(v)expr' statements. Perfect. Been looking for this for a while.
on the input side of IF everything from expr should work.
p.s. oh and right, comparison operators are not mentioned in the expr helpfile. ;)
Except "expr uses a C-like language" and comparison operators are, well, *operators* in C-derived languages.
+
-
/
*
%
==
!=
><
>=
&&
||
!
&
|
^<<
>>
~
sizeof(), address, and assignment operators aren't relevant in the context of [expr] or [if], so not included in the list. It occurs to me that the ternary operator ?: could be useful inside expr, but it's not supported (try it).