Coverage Report

Created: 2026-01-10 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/tools/fdlibm/s_trunc.c
Line
Count
Source
1
/* @(#)s_floor.c 5.1 93/09/24 */
2
/*
3
 * ====================================================
4
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * Developed at SunPro, a Sun Microsystems, Inc. business.
7
 * Permission to use, copy, modify, and distribute this
8
 * software is freely granted, provided that this notice
9
 * is preserved.
10
 * ====================================================
11
 */
12
13
//__FBSDID("$FreeBSD: src/lib/msun/src/s_trunc.c,v 1.4 2008/02/22 02:27:34 das Exp $");
14
15
/*
16
 * trunc(x)
17
 * Return x rounded toward 0 to integral value
18
 * Method:
19
 *  Bit twiddling.
20
 * Exception:
21
 *  Inexact flag raised if x not equal to trunc(x).
22
 */
23
24
25
#include "math_private.h"
26
27
static const double huge = 1.0e300;
28
29
double
30
s_trunc(double x)
31
14.8M
{
32
14.8M
  int32_t i0,i1,j0;
33
14.8M
  u_int32_t i;
34
14.8M
  EXTRACT_WORDS(i0,i1,x);
35
14.8M
  j0 = ((i0>>20)&0x7ff)-0x3ff;
36
14.8M
  if(j0<20) {
37
10.7M
      if(j0<0) {   /* raise inexact if x != 0 */
38
1.86M
    if(huge+x>0.0) {/* |x|<1, so return 0*sign(x) */
39
1.86M
        i0 &= 0x80000000U;
40
1.86M
        i1 = 0;
41
1.86M
    }
42
8.89M
      } else {
43
8.89M
    i = (0x000fffff)>>j0;
44
8.89M
    if(((i0&i)|i1)==0) return x; /* x is integral */
45
1.26M
    if(huge+x>0.0) { /* raise inexact flag */
46
1.26M
        i0 &= (~i); i1=0;
47
1.26M
    }
48
1.26M
      }
49
10.7M
  } else if (j0>51) {
50
2.23M
      if(j0==0x400) return x+x;  /* inf or NaN */
51
1.59M
      else return x;   /* x is integral */
52
2.23M
  } else {
53
1.81M
      i = ((u_int32_t)(0xffffffff))>>(j0-20);
54
1.81M
      if((i1&i)==0) return x;  /* x is integral */
55
1.76k
      if(huge+x>0.0)   /* raise inexact flag */
56
1.76k
    i1 &= (~i);
57
1.76k
  }
58
3.13M
  INSERT_WORDS(x,i0,i1);
59
3.13M
  return x;
60
14.8M
}