Coverage Report

Created: 2025-12-14 06:18

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
13.3M
{
32
13.3M
  int32_t i0,i1,j0;
33
13.3M
  u_int32_t i;
34
13.3M
  EXTRACT_WORDS(i0,i1,x);
35
13.3M
  j0 = ((i0>>20)&0x7ff)-0x3ff;
36
13.3M
  if(j0<20) {
37
10.0M
      if(j0<0) {   /* raise inexact if x != 0 */
38
1.27M
    if(huge+x>0.0) {/* |x|<1, so return 0*sign(x) */
39
1.27M
        i0 &= 0x80000000U;
40
1.27M
        i1 = 0;
41
1.27M
    }
42
8.74M
      } else {
43
8.74M
    i = (0x000fffff)>>j0;
44
8.74M
    if(((i0&i)|i1)==0) return x; /* x is integral */
45
1.12M
    if(huge+x>0.0) { /* raise inexact flag */
46
1.12M
        i0 &= (~i); i1=0;
47
1.12M
    }
48
1.12M
      }
49
10.0M
  } else if (j0>51) {
50
1.39M
      if(j0==0x400) return x+x;  /* inf or NaN */
51
931k
      else return x;   /* x is integral */
52
1.96M
  } else {
53
1.96M
      i = ((u_int32_t)(0xffffffff))>>(j0-20);
54
1.96M
      if((i1&i)==0) return x;  /* x is integral */
55
2.48k
      if(huge+x>0.0)   /* raise inexact flag */
56
2.48k
    i1 &= (~i);
57
2.48k
  }
58
2.40M
  INSERT_WORDS(x,i0,i1);
59
2.40M
  return x;
60
13.3M
}