[PD] long int precision lost

Martin Peach martinrp at vax2.concordia.ca
Mon Dec 6 17:22:56 CET 2004


Marc Boon wrote:

> chris clepper wrote:
> 
>> On Dec 6, 2004, at 2:34 AM, Marc Boon wrote:
>>
>>>
>>> to deal with this bad practice, you could define both:
>>>
>>> #define t_float double
>>> #define float double
>>
>>
>>
>> That second one probably won't work with any compiler.  Redefining 
>> basic data types should not be allowed - they are reserved for a 
>> reason.  If nothing else, #define float double is a million times 
>> worse bad practice compared to what you are trying to fix.  Donald 
>> Knuth would murder you on the spot for doing that. ;)
> 
> 
> #define float double
> int main(int argc, char* argv[]) {
>   printf("sizeof(float) = %d\n", sizeof(float));
>   printf("sizeof(double) = %d\n", sizeof(double));
>   return 0;
> }
> 
> prints:
> sizeof(float) = 8
> sizeof(double) = 8
> 
> without the #define, it prints:
> sizeof(float) = 4
> sizeof(double) = 8
> 
> 
Yes this works fine because the preprocessor replaces every instance of 
'float' with double just like a search and replace operation in a text 
editor. The real problems are going to show up where people have used an 
integer like 0x7FFFFFFF to fill a float variable, or in the case of the 
OSC parser, where a float is treated as an int for purposes of unloading 
the buffer -- both of these are sloppy programming practice exactly 
because they work at the time but cause trouble when either the 
representation or the container change.

Martin





More information about the Pd-list mailing list