我要评分
获取效率
正确性
完整性
易理解

scalb

Compute the result of x * 2^y.

Interface Definition

C interface:

float scalbf(float x, float y);

double scalb(double x, double y);

long double scalb(long double x, long double y);

Parameters

Parameter

Type

Description

Input/Output

x

  • For scalbf, x is of single-precision floating-point type.
  • For scalb, x is of double-precision floating-point type.
  • For scalbl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

y

  • For scalbf, y is of single-precision floating-point type.
  • For scalb, y is of double-precision floating-point type.
  • For scalbl, y is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • If x is NaN and y is any value, the return value is x*y.
  • If y is NaN or +∞ and x is any value, the return value is x*y.
  • If x is ±0 and y is -∞, the return value is x.
  • If y is -∞ and x is not 0, the return value is ±0 (with the same sign as x).
  • If y is a non-integer number and x is any value, the return value is NaN.

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 2.0, x4 = 1100.0;
    double y1 = -0.0, y2 = 0.0, y3 = 3.0, y4 = 2.1;
    // special handing
    double a = INFINITY, b = -INFINITY, c = NAN;
    printf("scalb(0.0, -0.0) = %.15f\n", scalb(x1, y1));
    printf("scalb(-0.0, 0.0) = %.15f\n", scalb(x2, y2));
    printf("scalb(2.0, 3.0) = %.15f\n", scalb(x3, y3));
    printf("scalb(2.0, 2.1) = %.15f\n", scalb(x3, y4));
    printf("scalb(0.0, -INFINITY) = %.15f\n", scalb(x1, b));
    printf("scalb(-0.0, -INFINITY) = %.15f\n", scalb(y1, b));
    printf("scalb(2.0, -INFINITY) = %.15f\n", scalb(x3, b));
    printf("scalb(2.0, 1100.0) = %.15f\n", scalb(x3, x4));
    printf("scalb(INFINITY, 2.0) = %.15f\n", scalb(a, x2));
    printf("scalb(-INFINITY, 2.0) = %.15f\n", scalb(b, x2));
    printf("scalb(NAN, 2.0) = %.15f\n", scalb(c, x3));
    printf("scalb(NAN, INFINITY) = %.15f\n", scalb(c, a));
    printf("scalb(NAN, -INFINITY) = %.15f\n", scalb(c, b));
    printf("scalb(INFINITY, -INFINITY) = %.15f\n", scalb(a, b));
    /* 
     * scalb(0.0, -0.0) = 0.000000000000000
     * scalb(-0.0, 0.0) = -0.000000000000000
     * scalb(2.0, 3.0) = 16.000000000000000
     * scalb(2.0, 2.1) = nan
     * scalb(0.0, -INFINITY) = 0.000000000000000
     * scalb(-0.0, -INFINITY) = -0.000000000000000
     * scalb(2.0, -INFINITY) = 0.000000000000000
     * scalb(2.0, 1100.0) = inf
     * scalb(INFINITY, 2.0) = inf
     * scalb(-INFINITY, 2.0) = -inf
     * scalb(NAN, 2.0) = nan
     * scalb(NAN, INFINITY) = nan
     * scalb(NAN, -INFINITY) = nan
     * scalb(INFINITY, -INFINITY) = nan
     * 
     * */