[PD-dev] freeverb's type-punned pointers

Mathieu Bouchard matju at artengine.ca
Sat Dec 8 02:10:45 CET 2007


On Fri, 7 Dec 2007, Hans-Christoph Steiner wrote:

> I want to fix the type-punned pointer problem in freeverb~ so it can
> be compiled with full optimization.  Here's the code snippets in
> question, with the warnings being issued for the FIX_DENORM_NAN_FLOAT
> () lines:
> #define IS_DENORM_FLOAT(v)  ((((*(unsigned long*)&(v))&0x7f800000)==0)
> &&((v)!=0.f))

*(unsigned long *) causes the problem. Is there any other reliable way to 
test for denormals? I don't know one. Maybe just something along 
the lines of abs(v)<1.175494e-38 ? I don't know either.

> Could I just cast things to (unsigned long)?  Or is there a better way?

No, (unsigned long) never does anything similar to (unsigned long *).

If you cast either the float or the float* to (unsigned long) you get 
completely useless information that you can't test denormals with. (in the 
latter case you can still cast back to pointer, but in the former case you 
just rounded too much and it's all destroyed)

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada


More information about the Pd-dev mailing list