Floating Point modulo Function

Source: Internet
Author: User

In addition to the default % modulo, the math library of C ++ also has a template function float fmod (float _ x, float _ y), which is used to modulo floating point numbers.

% Can only modulo int

There is also a MODF Function

Float

MODF (float _ x, float * _ iptr)
{Return _ builtin_modff (_ x, _ iptr );}
It can break down floating point numbers into integers and decimals.
 

Double A = 5;

Double B = 2.2;

// Double C = A % B; // This method can only be used for int

// Double C = MODF (A, & B); // splits floating point number A into an integer part and a decimal part, returns the decimal part, and stores the integer part in the memory specified by B.

Double C1 = fmod (a, B); // calculate the remainder of A/B and return a-n * B, with the same symbol as. N = [A/B] (returns an integer to the left zero ). The remainder is the same as the % operation value of C #.


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.