Path: blob/master/src/java.base/share/native/libfdlibm/s_ceil.c
41152 views
/*1* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* ceil(x)27* Return x rounded toward -inf to integral value28* Method:29* Bit twiddling.30* Exception:31* Inexact flag raised if x not equal to ceil(x).32*/3334#include "fdlibm.h"3536#ifdef __STDC__37static const double huge = 1.0e300;38#else39static double huge = 1.0e300;40#endif4142#ifdef __STDC__43double ceil(double x)44#else45double ceil(x)46double x;47#endif48{49int i0,i1,j0;50unsigned i,j;51i0 = __HI(x);52i1 = __LO(x);53j0 = ((i0>>20)&0x7ff)-0x3ff;54if(j0<20) {55if(j0<0) { /* raise inexact if x != 0 */56if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */57if(i0<0) {i0=0x80000000;i1=0;}58else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}59}60} else {61i = (0x000fffff)>>j0;62if(((i0&i)|i1)==0) return x; /* x is integral */63if(huge+x>0.0) { /* raise inexact flag */64if(i0>0) i0 += (0x00100000)>>j0;65i0 &= (~i); i1=0;66}67}68} else if (j0>51) {69if(j0==0x400) return x+x; /* inf or NaN */70else return x; /* x is integral */71} else {72i = ((unsigned)(0xffffffff))>>(j0-20);73if((i1&i)==0) return x; /* x is integral */74if(huge+x>0.0) { /* raise inexact flag */75if(i0>0) {76if(j0==20) i0+=1;77else {78j = i1 + (1<<(52-j0));79if(j<i1) i0+=1; /* got a carry */80i1 = j;81}82}83i1 &= (~i);84}85}86__HI(x) = i0;87__LO(x) = i1;88return x;89}909192