Ceil () [C language library function source code]

Source: Internet
Author: User

[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;

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.