---
title: tgamma
description: "返回入参x的伽马函数值。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0326.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0326.html
indexId: a0ea71e7466dfd5c11a795c898f7694f2b46632321ccbb040ad163c3b444b7ac74
---
# tgamma

返回入参x的伽马函数值。

#### 接口定义

C interface：

float tgammaf(float x);

float tgammaf_18(float x); // 仅在高精度版本提供


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| x | 在tgammaf中，x是单精度浮点类型。 在tgammaf\_18中，x是单精度浮点类型。 | 表示输入数据的浮点值。 | 输入 |


#### 返回值

返回x的伽马函数值y，y ∈ (-INF, +INF)。

- 输入x为±0，返回±inf。
- 输入x为负整数，返回-nan。
- 输入x为nan，返回nan。
- 输入x为+inf，返回+inf。
- 输入x为-inf，返回-nan。


#### 依赖

C: "km.h"


#### 示例

C interface：
```
// typical usage
float x1 = -2.5, x2 = -1.5, x3 = 1.5, x4 = 2.5;
// special handing
float a = -2.0, b = -0.0, c = INFINITY, d = NAN;
// print result
printf("tgammaf(-2.5) = %.15f\n", tgammaf(x1));
printf("tgammaf(-1.5) = %.15f\n", tgammaf(x2));
printf("tgammaf(1.5) = %.15f\n", tgammaf(x3));
printf("tgammaf(2.5) = %.15f\n", tgammaf(x4));
printf("tgammaf(-2.0) = %.15f\n", tgammaf(a));
printf("tgammaf(-0.0) = %.15f\n", tgammaf(b));
printf("tgammaf(INFINITY) = %.15f\n", tgammaf(c));
printf("tgammaf(NAN) = %.15f\n", tgammaf(d));
/*
*
*  tgammaf(-2.5) = -0.945308744907379
*  tgammaf(-1.5) = 2.363271713256836
*  tgammaf(1.5) = 0.886226952075958
*  tgammaf(2.5) = 1.329340338706970
*  tgammaf(-2.0) = -nan
*  tgammaf(-0.0) = -inf
*  tgammaf(INFINITY) = inf
*  tgammaf(NAN) = nan
*
* */
```
