7.4.8 <mathf.h>

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.

Type

Definition Name

Description

Constant
(macro)

EDOM

Indicates the value to be set in errno if the value of a parameter input to a function is outside the range of values defined in the function.

ERANGE

Indicates the value to be set in errno if the result of a function cannot be represented as a float type value, or if an overflow or an underflow occurs.

HUGE_VALF

Indicates the value for the function return value if the result of a function overflows.

Function

acosf

Calculates the arc cosine of a floating-point number.

asinf

Calculates the arc sine of a floating-point number.

atanf

Calculates the arc tangent of a floating-point number.

atan2f

Calculates the arc tangent of the result of a division of two floating-point numbers.

cosf

Calculates the cosine of a floating-point radian value.

sinf

Calculates the sine of a floating-point radian value.

tanf

Calculates the tangent of a floating-point radian value.

coshf

Calculates the hyperbolic cosine of a floating-point number.

sinhf

Calculates the hyperbolic sine of a floating-point number.

tanhf

Calculates the hyperbolic tangent of a floating-point number.

expf

Calculates the exponential function of a floating-point number.

frexpf

Breaks a floating-point number into a [0.5, 1.0) value and a power of 2.

ldexpf

Multiplies a floating-point number by a power of 2.

logf

Calculates the natural logarithm of a floating-point number.

log10f

Calculates the base-ten logarithm of a floating-point number.

modff

Breaks a floating-point number into integral and fractional parts.

powf

Calculates a power of a floating-point number.

sqrtf

Calculates the positive square root of a floating-point number.

ceilf

Calculates the smallest integral value not less than or equal to the given floating-point number.

fabsf

Calculates the absolute value of a floating-point number.

floorf

Calculates the largest integral value not greater than or equal to the given floating-point number.

fmodf

Calculates the remainder of a division of two floating-point numbers.

Operation in the event of an error is described below.

(1)

Domain error

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.

(2)

Range error

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.

Notes 1.

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.

[Format]

.

.

.

1 x=asinf(a);

2 if (errno==EDOM)

3 printf ("error\n");

4 else

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.

Notes 2.

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

Item

Compiler 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

Not specified

Whether a range error occurs if the second argument in the fmodf function is 0

A range error occurs.

 

acosf

Calculates the arc cosine of a floating-point number.

[Format]

#include <mathf.h>
float acosf (float f);

[Parameters]

f Floating-point number for which arc cosine is to be computed

[Return values]

Normal: Arc cosine of f

Abnormal: Domain error: Returns not-a-number.

[Remarks]

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.

 

asinf

Calculates the arc sine of a floating-point number.

[Format]

#include <mathf.h>
float asinf (float f);

[Parameters]

f Floating-point number for which arc sine is to be computed

[Return values]

Normal: Arc sine of f

Abnormal: Domain error: Returns not-a-number.

[Remarks]

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.

atanf

Calculates the arc tangent of a floating-point number.

[Format]

#include <mathf.h>
float atanf (float f);

[Parameters]

f Floating-point number for which arc tangent is to be computed

[Return values]

Arc tangent of f

[Remarks]

The atanf function returns the arc tangent in the range (–π/2, +π/2) by the radian.

 

atan2f

 

Calculates the arc tangent of the division of two floating-point numbers.

[Format]

#include <mathf.h>
float atan2f (float y, float x);

[Parameters]

x Divisor

y Dividend

[Return values]

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.

[Remarks]

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 7.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.

Figure 7.2

Meaning of atan2f Function

 

cosf

Calculates the cosine of a floating-point radian value.

[Format]

#include <mathf.h>
float cosf (float f);

[Parameters]

f Radian value for which cosine is to be computed

[Return values]

Cosine of f

 

sinf

Calculates the sine of a floating-point radian value.

[Format]

#include <mathf.h>
float sinf (float f);

[Parameters]

f Radian value for which sine is to be computed

[Return values]

Sine of f

 

tanf

Calculates the tangent of a floating-point radian value.

[Format]

#include <mathf.h>
float tanf (float f);

[Parameters]

f Radian value for which tangent is to be computed

[Return values]

Tangent of f

 

coshf

Calculates the hyperbolic cosine of a floating-point number.

[Format]

#include <mathf.h>
float coshf (float f);

[Parameters]

f Floating-point number for which hyperbolic cosine is to be computed

[Return values]

Hyperbolic cosine of f

 

sinhf

Calculates the hyperbolic sine of a floating-point number.

[Format]

#include <mathf.h>
float sinhf (float f);

[Parameters]

f Floating-point number for which hyperbolic sine is to be computed

[Return values]

Hyperbolic sine of f

 

tanhf

Calculates the hyperbolic tangent of a floating-point number.

[Format]

#include <mathf.h>
float tanhf (float f);

[Parameters]

f Floating-point number for which hyperbolic tangent is to be computed

[Return values]

Hyperbolic tangent of f

 

expf

Calculates the exponential function of a floating-point number.

[Format]

#include <mathf.h>
float expf (float f) ;

[Parameters]

f Floating-point number for which exponential function is to be computed

[Return values]

Exponential function value of f

 

frexpf

Breaks a floating-point number into a [0.5, 1.0) value and a power of 2.

[Format]

#include <mathf.h>
float frexpf (float value, float long *exp);

[Parameters]

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

[Return values]

If value is 0.0: 0.0

If value is not 0.0: Value of ret defined by ret * 2value pointed to by exp = value

[Remarks]

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.

 

ldexpf

Multiplies a floating-point number by a power of 2.

[Format]

#include <mathf.h>
float ldexpf (float e, long f);

[Parameters]

e Floating-point number to be multiplied by a power of 2

f Power-of-2 value

[Return values]

Result of e * 2f operation

 

logf

Calculates the natural logarithm of a floating-point number.

[Format]

#include <mathf.h>
float logf (float f);

[Parameters]

f Floating-point number for which natural logarithm is to be computed

[Return values]

Normal: Natural logarithm of f

Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if f is negative.

A range error occurs if f is 0.0.

 

log10f

Calculates the base-ten logarithm of a floating-point number.

[Format]

#include <mathf.h>
float log10f (float f);

[Parameters]

f Floating-point number for which base-ten logarithm is to be computed

[Return values]

Normal: Base-ten logarithm of f

Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if f is negative.

A range error occurs if f is 0.0.

 

modff

Breaks a floating-point number into integral and fractional parts.

[Format]

#include <mathf.h>
float modff (float a, float *b);

[Parameters]

a Floating-point number to be broken into integral and fractional parts

b Pointer indicating storage area that stores integral part

[Return values]

Fractional part of a

 

powf

Calculates a power of a floating-point number.

[Format]

#include <mathf.h>
float powf (float x, float y);

[Parameters]

x Value to be raised to a power

y Power value

[Return values]

Normal: Value of x raised to the power y

Abnormal: Domain error: Returns not-a-number.

[Remarks]

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.

sqrtf

Calculates the positive square root of a floating-point number.

[Format]

#include <mathf.h>
float sqrtf (float f);

[Parameters]

f Floating-point number for which positive square root is to be computed

[Return values]

Normal: Positive square root of f

Abnormal: Domain error: Returns not-a-number.

[Remarks]

A domain error occurs if f is negative.

 

ceilf

Returns the smallest integral value not less than or equal to the given floating-point number.

[Format]

#include <mathf.h>
float ceilf (float f);

[Parameters]

f Floating-point number for which smallest integral value not less than that number is to be computed

[Return values]

Smallest integral value not less than or equal to f

[Remarks]

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.

 

fabsf

Calculates the absolute value of a floating-point number.

[Format]

#include <mathf.h>
float fabsf (float f);

[Parameters]

f Floating-point number for which absolute value is to be computed

[Return values]

Absolute value of f

 

floorf

Returns the largest integral value not greater than or equal to the given floating-point number.

[Format]

#include <mathf.h>
float floorf (float f);

[Parameters]

f Floating-point number for which largest integral value not greater than that number is to be computed

[Return values]

Largest integral value not greater than or equal to f

[Remarks]

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.

 

fmodf

Calculates the remainder of a division of two floating-point numbers.

[Format]

#include <mathf.h>
float fmodf (float x, float y);

[Parameters]

x Dividend

y Divisor

[Return values]

When y is 0.0: x

When y is not 0.0: Remainder of division of x by y

[Remarks]

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.