Rate This Document
Findability
Accuracy
Completeness
Readability

sincos

Compute the sine and cosine of a real number at the same time.

Interface Definition

C interface:

void sincosf(float x, float* sinx, float* cosx);

void sincos(double x, double* sinx, double* cosx);

Fortran interface:

CALL SINCOSF(X, SINX, COSX);

CALL SINCOS(X, SINX, COSX);

Parameters

Parameter

Type

Description

Input/Output

x

  • For sincosf, x is of the single-precision floating-point type.
  • For sincos, x is of the double-precision floating-point type.

Floating-point value of the radian angle

Input

sinx

  • For sincosf, x is of the single-precision floating-point type.
  • For sincos, x is of the double-precision floating-point type.

Output pointer sinx.

If the pointer is null, an undefined behavior occurs, and the interface does not verify the output pointer.

Output

cosx

  • For sincosf, x is of the single-precision floating-point type.
  • For sincos, x is of the double-precision floating-point type.

Output pointer cosx.

If the pointer is null, an undefined behavior occurs, and the interface does not verify the output pointer.

Output

Return Value

  1. The sine sinx and cosine cosx of the radian angle x are returned. sinx ∈ [-1, +1]; cosx ∈ [-1, +1]
  2. If the input is +0, the sine is +0 and the cosine is +1.
  3. If the input is -0, the sine is -0 and the cosine is +1.
  4. If the input is ±∞, the sine and cosine are both NaN.
  5. If the input is NaN, the sine and cosine are both NaN.

Dependencies

#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, cos1.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 
    !