Playing with the bits of floats

Marianne Mueller mrm%puffin at Sun.COM
Wed Jan 18 08:06:24 AEST 1989


Various people have been recommending things like

> 	  Define a union such as:
> 		typedef union
> 		{	double d;
> 			unsigned long u[2];
> 		} dblunion;
>

to let a programmer access/manipulate bits directly.

You might want to make sure that your machine doesn't penalize you on
caching.  Some machines cache only floating point values, and opt not
to cache things that have a union type.  (I think it was the compiler
that forced main memory loads/stores, not the hardware.) 

I once thought I was speeding up my program by using union types, but
it turned out I slowed it down significantly!



More information about the Comp.lang.c mailing list