[Oberon] FP

Peter De Wachter pdewacht at gmail.com
Tue Apr 15 14:49:22 CEST 2014

No, that wouldn't work. Every architecture does floating point 
differently. And RISC FP in particular doesn't implement the full IEEE 
standard, for example it doesn't support infinities and denormal 
numbers. The current code in the emulator isn't pretty or fast but at 
least it's accurate.

 > float *a = (float *)(&x);

And don't do that, that invokes undefined behavior. To emulate C++'s 
reinterpret_cast, use an union:

union { uint32_t x; float f; } float_hack;
float_hack.x = x;
return float_hack.f;

On 15-04-14 13:17, Jörg wrote:
> Hi all
> Indeed. The FP code in the emulator is an example of "backporting assembler
> to C". PdW could have taken the "normal" FP arithmetic offered by C and let
> the C compiler decide to generate the code.
> The FP format NW uses is the same as C, namely IEEE single precision.
> So, PdW could have written something like:
> uint32_t fp_add(uint32_t x, uint32_t y, bool u, bool v);
> {
>    float *a = (float *)(&x); /* aka reinterpret_cast in C++ */
>    float *b = (float *)(&y);
> /* do whatever you want to do with the FP numbers a and b */
>    float sum, prod;
>    sum = *a + *b;
>    prod = *a * *b;
> ...
> }
> Jörg

More information about the Oberon mailing list