Subject: trunc/truncf in NetBSD 3
To: None <>
From: Klaus Heinz <>
List: tech-userlevel
Date: 10/06/2007 13:06:17

trying to build emulators/qemu I found that it needs a function trunc()
which NetBSD 3 does not provide.

Based on the man page from NetBSD 4
  The trunc() and truncf() functions return the nearest integral value with
  magnitude less than or equal to |x|.  They are equivalent to rint() and
  rintf() respectively, in the FP_RZ rounding mode.

I came up with the following workaround:

  #include <ieeefp.h>
  #include <math.h>  

  trunc( double x) {
    fp_rnd rnd_mode = fpsetround(FP_RZ);    
    double result = rint(x); 
    rnd_mode = fpsetround(rnd_mode);        
    return result;
On the other hand, there is possible solution in

which duplicates the trunc() function from -current.

Any opinions?