sincos(), sincosf(), sincosl()
Calculate the sine and cosine of an angle
Synopsis:
#include <math.h>
void sincos( double x, double *sn, double *cs );
void sincosf( float x, float *sn, float *cs);
void sincosl( long double x, long double *sn, long double *cs );
Arguments:
- x
- The angle, in radians, for which you want to compute the sine and cosine.
- sn
- The sine of angle x.
- cs
- The cosine of angle x.
Library:
- libm
- The general-purpose math library.
- libm-sve
- A library that optimizes the code for ARMv8.2 chips that have Scalable Vector Extension hardware.
Your system requirements will determine how you should work with these libraries:
- If you want only selected processes to run with the SVE version, you can include both libraries in your OS image and use the -l m or -l m-sve option to qcc to link explicitly against the appropriate one.
- If you want all processes to use the SVE version, include libm-sve.so in your OS image and set up a symbolic link from libm.so to libm-sve.so. Use the -l m option to qcc to link against the library.
Description:
The sincos(), sincosf(), and sincosl() functions compute the sine and cosine of x in radians. These functions let argument reduction occur once instead of twice with independent calls to sin() and cos(). An argument with a large magnitude may yield a result with little or no significance.
To check for error situations, use feclearexcept() and fetestexcept(). For example:
- Call
feclearexcept(FE_ALL_EXCEPT)
before calling sincos(), sincosf(), or sincosl(). - On return, if
fetestexcept(FE_ALL_EXCEPT)
is nonzero, then an error has occurred.
Returns:
If x is: | These functions return: | Errors: |
---|---|---|
±0.0 | 0.0 (sn) and 1.0 (cs) | — |
±Inf | NaN | FE_INVALID |
NaN | NaN | — |
These functions raise FE_INEXACT if the FPU reports that the result can't be exactly represented as a floating-point number.
Examples:
#include <stdio.h>
#include <math.h>
#include <fenv.h>
#include <stdlib.h>
int main( void )
{
int except_flags;
double sin_result, cos_result;
feclearexcept(FE_ALL_EXCEPT);
sincos( 0.5, &sin_result, &cos_result);
printf( "%f %f\n", sin_result, cos_result);
except_flags = fetestexcept(FE_ALL_EXCEPT);
if(except_flags) {
/* An error occurred; handle it appropriately. */
}
return EXIT_SUCCESS;
}
produces the output:
0.479426 0.877583
Classification:
Safety: | |
---|---|
Cancellation point | No |
Signal handler | Yes |
Thread | Yes |