Rate This Document
Findability
Accuracy
Completeness
Readability

lgamma_r

Compute the natural logarithm of the absolute gamma value of x, with the sign of the gamma value also returned. The input parameter is a real number.

Interface Definition

C interface:

float lgammaf(float x);

double lgamma(double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For lgammaf, x is of single-precision floating-point type.
  • For lgamma, x is of double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The natural logarithm of the absolute gamma value of x and the sign of the gamma value are returned.
  • If the input is NaN, the output is NaN and the sign is 1.
  • If the input is +∞, the output is +∞ and the sign is 1.
  • If the input is –∞, the output is +∞ and the sign is 1.
  • If the input is +0, the output is +∞ and the sign is 1.
  • If the input is –0, the output is +∞ and the sign is –1.

Dependency

C: "km.h"

Example

C interface:
    // print result
    int sign=0;
    double res=0.0;
    res=lgamma_r(0.0, &sign);
    printf("lgamma_r(0.0, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-0.0, &sign);
    printf("lgamma_r(-0.0, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(0.25, &sign);
    printf("lgamma_r(0.25, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-0.25, &sign);
    printf("lgamma_r(-0.25, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(0.5, &sign);
    printf("lgamma_r(0.5, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-0.5, &sign);
    printf("lgamma_r(-0.5, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(1.0, &sign);
    printf("lgamma_r(1.0, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-1.0, &sign);
    printf("lgamma_r(-1.0, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(2.0, &sign);
    printf("lgamma_r(2.0, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-2.0, &sign);
    printf("lgamma_r(-2.0, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(INFINITY, &sign);
    printf("lgamma_r(INFINITY, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-INFINITY, &sign);
    printf("lgamma_r(-INFINITY, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(NAN, &sign);
    printf("lgamma_r(NAN, &sign) = %.15f, sign = %d\n", res, sign);
    res=lgamma_r(-NAN, &sign);
    printf("lgamma_r(-NAN, &sign) = %.15f, sign = %d\n", res, sign);
    /* 
     * lgamma_r(0.0, &sign) = inf, sign = 1
     * lgamma_r(-0.0, &sign) = inf, sign = -1
     * lgamma_r(0.25, &sign) = 1.288022524698077, sign = 1
     * lgamma_r(-0.25, &sign) = 1.589575312551186, sign = -1
     * lgamma_r(0.5, &sign) = 0.572364942924700, sign = 1
     * lgamma_r(-0.5, &sign) = 1.265512123484645, sign = -1
     * lgamma_r(1.0, &sign) = 0.000000000000000, sign = 1
     * lgamma_r(-1.0, &sign) = inf, sign = 1
     * lgamma_r(2.0, &sign) = 0.000000000000000, sign = 1
     * lgamma_r(-2.0, &sign) = inf, sign = 1
     * lgamma_r(INFINITY, &sign) = inf, sign = 1
     * lgamma_r(-INFINITY, &sign) = inf, sign = 1
     * lgamma_r(NAN, &sign) = nan, sign = 1
     * lgamma_r(-NAN, &sign) = -nan, sign = 1
     * 
     * */