Current location - Training Enrollment Network - Mathematics courses - Mathematical functions commonly used in iOS
Mathematical functions commonly used in iOS
If n decimal places are to be rounded. We can do this in the following ways:

Comparison of PS: ceil (), floor (), rint () and round ()

If you want to realize the interception of n decimal places. We can do this in the following ways:

This function returns the remainder r = x-n*y, where n is an integer truncated by the x/y value.

This function returns the remainder r = x-n*y, where n is equal to x/y, and the nearest integer is taken. If both numbers are close to x/y, then n is even.

From the above description, we can see that the main difference between fmod and remainder is that the integer part of x/y is treated differently: the fmod function takes the integer of x/y to calculate the remainder, and the Remainder function takes the integer closest to x/y to calculate the remainder.

This function is the same as the remainder function, except that the integer quotient is also returned to quo, that is, in the equation of r = x-n *y, R is returned as a function and N is returned to quo.

Function returns the decimal part, and the integer part is stored in p.

The function returns the mantissa * symbol part, and the exponent part is stored in P. What needs to be clear is that when floating-point number X is 0 or denormalized floating-point number, mantissa and exponent are returned according to the definition format of floating-point number, and when X is normalized floating-point number, the return value interval is [0.5, 1]. The return value and exponent value p here are different from the standardized floating-point number format introduced above: symbol * (1. Mantissa) * 2 exponent. Because the mantissa returned by definition should be 1.xxx, but the return value here is [0.5, 1]. In fact, this is not contradictory, but the function does special treatment for the return value: because a positive floating point number can be expressed as:1.m * 2 e = = > = > (2 0+0. m) * 2 e = >; (2^0/2+0 . m/2)*2^(e+ 1)= & gt; (0.5+0.5m/2) * 2 (e+1). So the true value returned by the frexp function is: mantissa divided by 2, and P stores the exponent+1.

Some examples of using the following functions:

This function and the ldexp function above are reciprocal functions. For a detailed understanding of floating-point storage formats, please refer to IEEE754.

Because the domain of arctan is (-∞, +∞), and the range is between (-/2, /2). Therefore:

Another meaning provided by this function is that the value of tan function is actually the result of dividing the opposite side by the adjacent side, so when the opposite side and the adjacent side are known, the corresponding radian value can be directly obtained by using this inverse trigonometric function. If the values of the opposite side and the adjacent side are both 0.0 under special circumstances, if atan(0.0/0.0) is called, the value will be NAN instead of 0. Because the value of 0.0/0.0 is NAN, and calling atan function on NAN returns NAN, but calling atan2 (0.0,0.0) returns the correct value of 0.