sincos
Compute the sine and cosine of the input radian at the same time.
Interface Definition
C interface:
void sincosf(float x, float* sinx, float* cosx);
void sincosf_18(float x, float* sinx, float* cosx);
void sincos(double x, double* sinx, double* cosx);
void sincosl(long double x, long double* sinx, long double* cosx);
sincosf_18 is provided only in the high-precision version.
Fortran interface:
CALL SINCOSF(X, SINX, COSX);
CALL SINCOS(X, SINX, COSX);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of a radian angle. |
Input |
sinx |
|
Output pointer sinx. If the pointer is null, an undefined behavior occurs, and the interface does not verify the output pointer. |
Output |
cosx |
|
Output pointer cosx. If the pointer is null, an undefined behavior occurs, and the interface does not verify the output pointer. |
Output |
Return Value
- The sine sinx and cosine cosx of the radian angle x are returned. sinx ∈ [-1, +1]; cosx ∈ [-1, +1]
- If the input is +0, the sine is +0 and the cosine is +1.
- If the input is -0, the sine is -0 and the cosine is +1.
- If the input is ±∞, the sine and cosine are both NaN.
- If the input is NaN, the sine and cosine are both NaN.
Dependency
#include "km.h"
Examples
C interface:
double pi = acos(-1);
// typical usage
double a = pi/6, b = 1.0, c = -3*pi/4, d = pi/3;
// special handling
double e = INFINITY, f = -INFINITY, g = NAN;
// print result
double sinx, cosx;
sincos(a, &sinx, &cosx);
printf("sin(pi/6) = %.15f, cos(pi/6) = %.15f\n", sinx, cosx);
sincos(b, &sinx,&cosx);
printf("sin(1.0) = %.15f, cos(1.0) = %.15f\n", sinx, cosx);
sincos(c, &sinx,&cosx);
printf("sin(-3*pi/4) = %.15f, cos(-3*pi/4) = %.15f\n", sinx, cosx);
sincos(d, &sinx,&cosx);
printf("sin(pi/3) = %.15f, cos(pi/3) = %.15f\n", sinx, cosx);
sincos(e, &sinx,&cosx);
printf("sin(INFINITY) = %.15f, cos(INFINITY) = %.15f\n", sinx, cosx);
sincos(f, &sinx,&cosx);
printf("sin(-INFINITY) = %.15f, cos(-INFINITY) = %.15f\n", sinx, cosx);
sincos(g, &sinx,&cosx);
printf("sin(NAN) = %.15f, cos(NAN) = %.15f\n", sinx, cosx);
/*
* sin(pi/6) = 0.500000000000000, cos(pi/6) = 0.866025403784439
* sin(1.0) = 0.841470984807897, cos(1.0) = 0.540302305868140
* sin(-3*pi/4) = -0.707106781186548, cos(-3*pi/4) = -0.707106781186547
* sin(pi/3) = 0.866025403784439, cos(pi/3) = 0.500000000000000
* sin(INFINITY) = -nan, cos(INFINITY) = nan
* sin(-INFINITY) = -nan, cos(-INFINITY) = nan
* sin(NAN) = nan, cos(NAN) = -nan
*
* */
Fortran interface:
REAL(8) :: X = 1.0
REAL(8), TARGET :: SINX, COSX
TYPE(C_PTR) :: PSINX, PCOSX
PSINX = C_LOC(SINX)
PCOSX = C_LOC(COSX)
CALL SINCOS(X, PSINX, PCOSX)
PRINT*, SINX, COSX
!
! OUTPUT
! 0.841470984807897 0.540302305868140
!