(root)/
glibc-2.38/
sysdeps/
ieee754/
ldbl-128ibm/
s_truncl.c
       1  /* Truncate (toward zero) long double floating-point values.
       2     IBM extended format long double version.
       3     Copyright (C) 2006-2023 Free Software Foundation, Inc.
       4     This file is part of the GNU C Library.
       5  
       6     The GNU C Library is free software; you can redistribute it and/or
       7     modify it under the terms of the GNU Lesser General Public
       8     License as published by the Free Software Foundation; either
       9     version 2.1 of the License, or (at your option) any later version.
      10  
      11     The GNU C Library is distributed in the hope that it will be useful,
      12     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14     Lesser General Public License for more details.
      15  
      16     You should have received a copy of the GNU Lesser General Public
      17     License along with the GNU C Library; if not, see
      18     <https://www.gnu.org/licenses/>.  */
      19  
      20  #define NO_MATH_REDIRECT
      21  #include <math.h>
      22  #include <math_private.h>
      23  #include <math_ldbl_opt.h>
      24  #include <float.h>
      25  #include <ieee754.h>
      26  
      27  double ceil (double) asm ("__ceil");
      28  double floor (double) asm ("__floor");
      29  double trunc (double) asm ("__trunc");
      30  
      31  
      32  long double
      33  __truncl (long double x)
      34  {
      35    double xh, xl, hi, lo;
      36  
      37    ldbl_unpack (x, &xh, &xl);
      38  
      39    /* Return Inf, Nan, +/-0 unchanged.  */
      40    if (__builtin_expect (xh != 0.0
      41  			&& __builtin_isless (__builtin_fabs (xh),
      42  					     __builtin_inf ()), 1))
      43      {
      44        hi = trunc (xh);
      45        if (hi != xh)
      46  	{
      47  	  /* The high part is not an integer; the low part does not
      48  	     affect the result.  */
      49  	  xh = hi;
      50  	  xl = 0;
      51  	}
      52        else
      53  	{
      54  	  /* The high part is a nonzero integer.  */
      55  	  lo = xh > 0 ? floor (xl) : ceil (xl);
      56  	  xh = hi;
      57  	  xl = lo;
      58  	  ldbl_canonicalize_int (&xh, &xl);
      59  	}
      60      }
      61    else
      62      /* Quiet signaling NaN arguments.  */
      63      xh += xh;
      64  
      65    return ldbl_pack (xh, xl);
      66  }
      67  
      68  long_double_symbol (libm, __truncl, truncl);