Rate This Document
Findability
Accuracy
Completeness
Readability

v?sqrt

Compute the element-wise square root of a vector.

Interface Definition

C interface:

void vssqrt(const int len, const float* src, float* dst);

void vdsqrt(const int len, const double* src, double* dst);

void vcsqrt(const int len, const float complex *src, float complex *dst);

void vzsqrt(const int len, const double complex *src, double complex *dst);

Fortran interface:

CALL VSSQRT(LEN, SRC, DST);

CALL VDSQRT(LEN, SRC, DST);

Parameters

Parameter

Type

Description

Input/Output

len

Integer

Number of elements in the input vector.

If len ≤ 0, the system displays a message indicating that the value of len is invalid.

Input

src

  • Single-precision floating-point type for vssqrt
  • Double-precision floating-point type for vdsqrt
  • Single-precision floating-point complex type for vcsqrt
  • Double-precision floating-point complex type for vzsqrt

Input vector src with length len.

If the pointer is null, the system prompts a null pointer error.

Input

dst

  • Single-precision floating-point type for vssqrt
  • Double-precision floating-point type for vdsqrt
  • Single-precision floating-point complex type for vcsqrt
  • Double-precision floating-point complex type for vzsqrt

Output vector dst with length len.

If the pointer is null, the system prompts a null pointer error.

Output

Return Value

  • The square root of a number is returned for each operation value. The value range is [0, +INF).
  • For vssqrt and vdsqrt, special output values are listed in the following table.

    Input Value (src)

    Output Value (dst)

    ±0

    ±0

    +inf

    +inf

    < 0

    nan

    nan

    nan

  • For vcsqrt and vzsqrt, the Euler formula and double angle formulas of trigonometric functions are used.

    , where .

    The following table lists the special values.

    RE(z)

    i * IM(z)

    -∞

    -X

    -0

    +0

    +X

    +∞

    NAN

    +i * ∞

    +∞+i*∞

    +∞+i*∞

    +∞+i*∞

    +∞+i*∞

    +∞+i*∞

    +∞+i*∞

    +∞+i*∞

    +i * Y

    +0+i*∞

               

    +∞+i*0

    QNAN+i*QNAN

    +i * 0

    +0+i*∞

      

    +0+i*0

    +0+i*0

      

    +∞+i*0

    QNAN+i*QNAN

    -i * 0

    +0-i*∞

      

    +0+i*0

    +0+i*0

      

    +∞-i*0

    QNAN+i*QNAN

    -i * Y

    +0-i*∞

               

    +∞-i*0

    QNAN+i*QNAN

    -i * ∞

    +∞-i*∞

    +∞-i*∞

    +∞-i*∞

    +∞-i*∞

    +∞-i*∞

    +∞-i*∞

    +∞-i*∞

    +i * NAN

    QNAN+i*∞

    QNAN+i*QNAN

    QNAN+i*QNAN

    QNAN+i*QNAN

    QNAN+i*QNAN

    +∞+i*QNAN

    QNAN+i*QNAN

Dependencies

C: "kvml.h"

Fortran: "kvml.f03"

Examples

C interface:

    int i, len = 4; 
    float src[len] = {0.0f, 0.25f, 16.0f, 1.0f}; 
    float* dst = (float*)malloc(sizeof(float) * len); 
    if (dst == NULL) { 
        printf("Malloc Failed!\n"); 
        return 0; 
    } 
    vssqrt(len, src, dst); 
    /** 
     *  Output dst: 
     *     0.0  0.5  4.0  1.0 
     * 
     */

Fortran interface:

    INTEGER :: LEN = 4 
    REAL(4) SRC(4)  
    REAL(4) DST(4) 
    DATA SRC /1, 2, 3, 4/ 
    CALL VSSQRT(LEN, SRC1, SRC2, DST) 
    !  
    ! OUTPUT DST: 
    !     1.000000000, 1.414213538, 1.732050776, 2.000000000 
    !