Coverage Report

Created: 2026-03-16 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/moddable/xs/tools/fdlibm/s_ceil.c
Line
Count
Source
1
/* @(#)s_ceil.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_ceil.c,v 1.11 2008/02/15 07:01:40 bde Exp $");
14
15
/*
16
 * ceil(x)
17
 * Return x rounded toward -inf to integral value
18
 * Method:
19
 *  Bit twiddling.
20
 * Exception:
21
 *  Inexact flag raised if x not equal to ceil(x).
22
 */
23
24
#include "math_private.h"
25
26
static const double huge = 1.0e300;
27
28
double
29
s_ceil(double x)
30
592k
{
31
592k
  int32_t i0,i1,j0;
32
592k
  u_int32_t i,j;
33
592k
  EXTRACT_WORDS(i0,i1,x);
34
592k
  j0 = ((i0>>20)&0x7ff)-0x3ff;
35
592k
  if(j0<20) {
36
582k
      if(j0<0) {   /* raise inexact if x != 0 */
37
29.9k
    if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
38
29.9k
        if(i0<0) {i0=0x80000000;i1=0;}
39
29.1k
        else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
40
29.9k
    }
41
552k
      } else {
42
552k
    i = (0x000fffff)>>j0;
43
552k
    if(((i0&i)|i1)==0) return x; /* x is integral */
44
255k
    if(huge+x>0.0) { /* raise inexact flag */
45
255k
        if(i0>0) i0 += (0x00100000)>>j0;
46
255k
        i0 &= (~i); i1=0;
47
255k
    }
48
255k
      }
49
582k
  } else if (j0>51) {
50
9.47k
      if(j0==0x400) return x+x;  /* inf or NaN */
51
3
      else return x;   /* x is integral */
52
9.47k
  } else {
53
4
      i = ((u_int32_t)(0xffffffff))>>(j0-20);
54
4
      if((i1&i)==0) return x;  /* x is integral */
55
3
      if(huge+x>0.0) {     /* raise inexact flag */
56
3
    if(i0>0) {
57
3
        if(j0==20) i0+=1;
58
2
        else {
59
2
      j = i1 + (1<<(52-j0));
60
2
      if(j<(u_int32_t)i1) i0+=1; /* got a carry */
61
2
      i1 = j;
62
2
        }
63
3
    }
64
3
    i1 &= (~i);
65
3
      }
66
3
  }
67
285k
  INSERT_WORDS(x,i0,i1);
68
285k
  return x;
69
592k
}