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);

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

  • For vssqrt, src is of the single-precision floating-point type.
  • For vdsqrt, src is of the double-precision floating-point type.

Input vector src with length len.

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

Input

dst

  • For vssqrt, dst is of the single-precision floating-point type.
  • For vdsqrt, dst is of the double-precision floating-point type.

Output vector dst with length len.

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

Output

Return Value

  1. The square root of a number is returned for each operation value. The value range is [0, +INF).
  2. If the value of src is ±0, the value of dst is ±0.
  3. If the value of src is less than +0, the value of dst is NaN.
  4. If the value of src is +∞, the value of dst is +∞.
  5. If the value of src is NaN, the value of dst is NaN.

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 
    !