brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · c379cd1 Raw
71 lines · plain
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include <clc/float/definitions.h>10#include <clc/internal/clc.h>11#include <clc/math/clc_exp.h>12#include <clc/math/clc_fabs.h>13#include <clc/math/clc_lgamma.h>14#include <clc/math/clc_sinpi.h>15#include <clc/math/math.h>16 17_CLC_OVERLOAD _CLC_DEF float __clc_tgamma(float x) {18  const float pi = 3.1415926535897932384626433832795f;19  float absx = __clc_fabs(x);20  float lg = __clc_lgamma(absx);21  float g = __clc_exp(lg);22 23  if (x < 0.0f) {24    float z = __clc_sinpi(x);25    g = g * absx * z;26    g = pi / g;27    g = g == 0 ? INFINITY : g;28    g = z == 0 ? FLT_NAN : g;29  }30 31  return g;32}33 34#ifdef cl_khr_fp6435 36#pragma OPENCL EXTENSION cl_khr_fp64 : enable37 38_CLC_OVERLOAD _CLC_DEF double __clc_tgamma(double x) {39  const double pi = 3.1415926535897932384626433832795;40  double absx = __clc_fabs(x);41  double lg = __clc_lgamma(absx);42  double g = __clc_exp(lg);43 44  if (x < 0.0) {45    double z = __clc_sinpi(x);46    g = g * absx * z;47    g = pi / g;48    g = g == 0 ? INFINITY : g;49    g = z == 0 ? DBL_NAN : g;50  }51 52  return g;53}54 55#endif56 57#ifdef cl_khr_fp1658 59#pragma OPENCL EXTENSION cl_khr_fp16 : enable60 61// Forward the half version of this builtin onto the float one62_CLC_OVERLOAD _CLC_DEF half __clc_tgamma(half x) {63  return (half)__clc_tgamma((float)x);64}65 66#endif67 68#define __CLC_FUNCTION __clc_tgamma69#define __CLC_BODY <clc/shared/unary_def_scalarize.inc>70#include <clc/math/gentype.inc>71