[C language library function source code]
[This program is compiled in Dev C ++ 4.9.9.2]
Double my_ceil (Double X)
{
Register double ret;
Unsigned short int temp1, temp2;
_ ASM _ ("fnstcw % 0": "= m" (temp1 ));
Temp2 = (temp1 & 0xf3ff) | 0x0800;/* rounding up */
_ ASM _ ("fldcw % 0": "M" (temp2 ));
_ ASM _ ("frndint": "= T" (RET): "0" (x ));
_ ASM _ ("fldcw % 0": "M" (temp1 ));
Return ret;
} // Rounded up
// The following is the entire upward function written by myself.
Double my_ceil01 (Double X)
{
Double Y = X;
If (* (int *) & Y) + 1) & 0x80000000 )! = 0) // or if (x <0)
Return (float) (INT) X );
Else // discusses non-negative conditions.
{
If (x = 0)
Return (float) (INT) X );
Else
Return (float) (INT) x) + 1;
}
}
Int main ()
{
Double A = 88.8;
Printf ("Ceil (% F) = % F/N", A, my_ceil ());
A =-88.8;
Printf ("Ceil (% F) = % F/N", A, my_ceil ());
Printf ("****************************/N ");
A = 88.8;
Printf ("Ceil (% F) = % F/N", A, my_ceil01 ());
A =-88.8;
Printf ("Ceil (% F) = % F/N", A, my_ceil01 ());
System ("pause ");
Return 0;
}