# [PD] Expr does not play well with ints?

B. Bogart ben at ekran.org
Tue Jul 24 07:19:09 CEST 2007

```Ah! [expr float(8) / 6] does the trick, I'm damn happy there is float()
in there!!!

Thanks all,

B. Bogart

B. Bogart wrote:
> Mathieu, are you really able to put 8.0 in an expr argument? In my PD
> (.39 ubuntu package) the 8.0 gets turned into 8 and remains an int.
>
> Hmm?
>
> B. Bogart
>
> Mathieu Bouchard wrote:
>> On Mon, 23 Jul 2007, B. Bogart wrote:
>>
>>> So I've been doing lots of calculations with expr and creation
>>> arguments, and it seems to send an int when it should send a float way
>>> too often:
>>> [expr 8 / 20]
>>> returns 0!!!
>>> Have I lost my mind? Is my machine going crazy? or is expr actually
>>> doing what I see here?
>> expr supports the int type because [expr] comes from jMax/FTS/Max/etc.
>> So if you put a number without a dot it's parsed as an int. Then the
>> main difference between ints and floats is that an int divided by an int
>> is rounded towards zero (many languages do it like that but some others
>> round it always downwards instead; some others instead force the result
>> to be a float or a rational)
>>
>> What you can do is either [expr 8 / 20.0] or [expr 8.0 / 20] or
>> obviously [expr 8.0 / 20.0]
>>
>> You only need to make one of the two as float because float has priority
>> on int, so when a float comes into contact with an int, the int is
>> converted, even though float can't represent everything that int can,
>> e.g. compare
>>
>>   [expr 123456789%10] finds last digit of 123456789
>>   [expr int(123456789.0)%10] fails because float isn't that precise
>>
>> do not put a space before % in that first example! if you do, pd will
>> parse it as a number, turn it to float, then give it to [expr], which
>> determines that float % int = syntax error.
>>
>> cool, eh?
>>
>>  _ _ __ ___ _____ ________ _____________ _____________________ ...
>> | Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> PD-list at iem.at mailing list
>> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>
>
>
> _______________________________________________
> PD-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
>

```