Subject: trunc/truncf in NetBSD 3
To: None <tech-userlevel@NetBSD.org>
From: Klaus Heinz <k.heinz@oktsieben.kh-22.de>
List: tech-userlevel
Date: 10/06/2007 13:06:17
Hi,

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>  

  double 
  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
  http://www.NetBSD.org/cgi-bin/query-pr-single.pl?number=36602

which duplicates the trunc() function from -current.

Any opinions?

ciao
     Klaus