• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * This file has no copyright assigned and is placed in the Public Domain.
3  * This file is part of the mingw-w64 runtime package.
4  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5  */
6 #include <fenv.h>
7 #include <math.h>
8 
9 long double
truncl(long double _x)10 truncl (long double _x)
11 {
12 #if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
13   return trunc(_x);
14 #else
15   long double retval = 0.0L;
16   unsigned short saved_cw;
17   unsigned short tmp_cw;
18   __asm__ __volatile__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
19   tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
20 	    | FE_TOWARDZERO;
21   __asm__ __volatile__ ("fldcw %0;" : : "m" (tmp_cw));
22   __asm__ __volatile__ ("frndint;" : "=t" (retval)  : "0" (_x)); /* round towards zero */
23   __asm__ __volatile__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
24   return retval;
25 #endif /* defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__) */
26 }
27