Performs various mathematical operations.
<mathf.h> declares mathematical functions and defines macros in single-precision format. The mathematical functions and macros used here do not follow the ANSI specifications. Each function receives float-type arguments and returns a float-type value.
The following constants (macros) are all implementation-defined.
Operation in the event of an error is described below.
A domain error occurs if the value of a parameter input to a function is outside the domain over which the mathematical function is defined. In this case, the value of EDOM is set in errno. The function return value in implementation-defined.
A range error occurs if the result of a function cannot be represented as a float type value. In this case, the value of ERANGE is set in errno. If the result overflows, the function returns the value of HUGE_VALF, with the same sign as the correct value of the function. If the result underflows, 0 is returned as the return value.
If there is a possibility of a domain error resulting from a <mathf.h> function call, it is dangerous to use the resultant value directly. The value of errno should always be checked before using the result in such cases. |
5 printf ("result is : %f\n",x);
In line 1, the arc sine value is computed using the asinf function. If the value of argument a is outside the asinf function domain [–1.0, 1.0], the EDOM value is set in errno. Line 2 determines whether a domain error has occurred. If a domain error has occurred, error is output in line 3. If there is no domain error, the arc sine value is output in line 5.
Whether or not a range error occurs depends on the internal representation format of floating-point types determined by the compiler. For example, if an internal representation format that allows an infinity to be represented as a value is used, <mathf.h> library functions can be implemented without causing range errors. |
Implementation-Defined Specifications
Value returned by a mathematical function if an input argument is out of the range |
A not-a-number is returned. For details on the format of not-a-numbers, refer to section 4.1.5 (5) Floating-Point Number Specifications. |
Whether errno is set to the value of macro ERANGE if an underflow error occurs in a mathematical function |
|
Whether a range error occurs if the second argument in the fmodf function is 0 |
Calculates the arc cosine of a floating-point number.
#include <mathf.h>
float acosf (float f);
f Floating-point number for which arc cosine is to be computed
Abnormal: Domain error: Returns not-a-number.
A domain error occurs for a value of f not in the range [–1.0, +1.0]
The acosf function returns the arc cosine in the range [0, π] by the radian.
Calculates the arc sine of a floating-point number.
#include <mathf.h>
float asinf (float f);
f Floating-point number for which arc sine is to be computed
Abnormal: Domain error: Returns not-a-number.
A domain error occurs for a value of f not in the range [–1.0, +1.0].
The asinf function returns the arc sine in the range [–π/2, +π/2] by the radian.
Calculates the arc tangent of a floating-point number.
#include <mathf.h>
float atanf (float f);
f Floating-point number for which arc tangent is to be computed
The atanf function returns the arc tangent in the range (–π/2, +π/2) by the radian.
Calculates the arc tangent of the division of two floating-point numbers.
#include <mathf.h>
float atan2f (float y, float x);
Normal: Arc tangent value when y is divided by x
Abnormal: Domain error: Returns not-a-number.
Error conditions: A domain error occurs if the values of both x and y are 0.0.
A domain error occurs if the values of both x and y are 0.0.
The atan2f function returns the arc tangent in the range (–π, +π) by the radian. The meaning of the atan2f function is illustrated in figure 6.2. As shown in the figure, the result of the atan2f function is the angle between the X-axis and a straight line passing through the origin and point (x, y).
If y = 0.0 and x is negative, the result is π. If x = 0.0, the result is ±π/2, depending on whether y is positive or negative.
Calculates the cosine of a floating-point radian value.
#include <mathf.h>
float cosf (float f);
f Radian value for which cosine is to be computed
Calculates the sine of a floating-point radian value.
#include <mathf.h>
float sinf (float f);
f Radian value for which sine is to be computed
Calculates the tangent of a floating-point radian value.
#include <mathf.h>
float tanf (float f);
f Radian value for which tangent is to be computed
Calculates the hyperbolic cosine of a floating-point number.
#include <mathf.h>
float coshf (float f);
f Floating-point number for which hyperbolic cosine is to be computed
Calculates the hyperbolic sine of a floating-point number.
#include <mathf.h>
float sinhf (float f);
f Floating-point number for which hyperbolic sine is to be computed
Calculates the hyperbolic tangent of a floating-point number.
#include <mathf.h>
float tanhf (float f);
f Floating-point number for which hyperbolic tangent is to be computed
Calculates the exponential function of a floating-point number.
#include <mathf.h>
float expf (float f) ;
f Floating-point number for which exponential function is to be computed
Exponential function value of f
Breaks a floating-point number into a [0.5, 1.0) value and a power of 2.
#include <mathf.h>
float frexpf (float value, float long *exp);
value Floating-point number to be broken into a [0.5, 1.0) value and a power of 2
exp Pointer to storage area that holds power-of-2 value
If value is not 0.0: Value of ret defined by ret * 2value pointed to by exp = value
The frexpf function breaks value into a [0.5, 1.0) value and a power of 2. It stores the resultant power-of-2 value in the area pointed to by exp.
The frexpf function returns the return value ret in the range [0.5, 1.0) or as 0.0.
If value is 0.0, the contents of the int storage area pointed to by exp and the value of ret are both 0.0.
Multiplies a floating-point number by a power of 2.
#include <mathf.h>
float ldexpf (float e, long f);
e Floating-point number to be multiplied by a power of 2
Calculates the natural logarithm of a floating-point number.
#include <mathf.h>
float logf (float f);
f Floating-point number for which natural logarithm is to be computed
Normal: Natural logarithm of f
Abnormal: Domain error: Returns not-a-number.
A domain error occurs if f is negative.
A range error occurs if f is 0.0.
Calculates the base-ten logarithm of a floating-point number.
#include <mathf.h>
float log10f (float f);
f Floating-point number for which base-ten logarithm is to be computed
Normal: Base-ten logarithm of f
Abnormal: Domain error: Returns not-a-number.
A domain error occurs if f is negative.
A range error occurs if f is 0.0.
Breaks a floating-point number into integral and fractional parts.
#include <mathf.h>
float modff (float a, float *b);
a Floating-point number to be broken into integral and fractional parts
b Pointer indicating storage area that stores integral part
Calculates a power of a floating-point number.
#include <mathf.h>
float powf (float x, float y);
x Value to be raised to a power
Normal: Value of x raised to the power y
Abnormal: Domain error: Returns not-a-number.
A domain error occurs if x is 0.0 and y is 0.0 or less, or if x is negative and y is not an integer.
Calculates the positive square root of a floating-point number.
#include <mathf.h>
float sqrtf (float f);
f Floating-point number for which positive square root is to be computed
Normal: Positive square root of f
Abnormal: Domain error: Returns not-a-number.
A domain error occurs if f is negative.
Returns the smallest integral value not less than or equal to the given floating-point number.
#include <mathf.h>
float ceilf (float f);
f Floating-point number for which smallest integral value not less than that number is to be computed
Smallest integral value not less than or equal to f
The ceilf function returns the smallest integral value not less than or equal to f, expressed as a float type value. Therefore, if f is negative, the value after truncation of the fractional part is returned.
Calculates the absolute value of a floating-point number.
#include <mathf.h>
float fabsf (float f);
f Floating-point number for which absolute value is to be computed
Returns the largest integral value not greater than or equal to the given floating-point number.
#include <mathf.h>
float floorf (float f);
f Floating-point number for which largest integral value not greater than that number is to be computed
Largest integral value not greater than or equal to f
The floorf function returns the largest integral value not greater than or equal to f, expressed as a float type value. Therefore, if f is negative, the value after rounding-up of the fractional part is returned.
Calculates the remainder of a division of two floating-point numbers.
#include <mathf.h>
float fmodf (float x, float y);
When y is not 0.0: Remainder of division of x by y
In the fmodf function, the relationship between parameters x and y and return value ret is as follows:
x = y * i + ret (where i is an integer)
The sign of return value ret is the same as the sign of x.
If the quotient of x/y cannot be represented, the value of the result is not guaranteed.