1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * These math functions are taken from newlib-nano-2, the newlib/libm/math
5  * directory, available from https://github.com/32bitmicro/newlib-nano-2.
6  *
7  * Appropriate copyright headers are reproduced below.
8  */
9 
10 /* w_gammaf.c -- float version of w_gamma.c.
11  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
12  */
13 
14 /*
15  * ====================================================
16  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
17  *
18  * Developed at SunPro, a Sun Microsystems, Inc. business.
19  * Permission to use, copy, modify, and distribute this
20  * software is freely granted, provided that this notice
21  * is preserved.
22  * ====================================================
23  */
24 
25 #include "math.h"
26 #include "fdlibm.h"
27 #define _IEEE_LIBM 1
28 
29 #ifdef __STDC__
tgammaf(float x)30 	float tgammaf(float x)
31 #else
32 	float tgammaf(x)
33 	float x;
34 #endif
35 {
36         float y;
37 	int local_signgam;
38 	if (!isfinite(x)) {
39 	  /* special cases: tgammaf(nan)=nan, tgammaf(inf)=inf, tgammaf(-inf)=nan */
40 	  return x + INFINITY;
41 	}
42 	y = expf(__ieee754_lgammaf_r(x,&local_signgam));
43 	if (local_signgam < 0) y = -y;
44 #ifdef _IEEE_LIBM
45 	return y;
46 #else
47 	if(_LIB_VERSION == _IEEE_) return y;
48 
49 	if(!finitef(y)&&finitef(x)) {
50 	  if(floorf(x)==x&&x<=(float)0.0)
51 	    /* tgammaf pole */
52 	    return (float)__kernel_standard((double)x,(double)x,141);
53 	  else
54 	    /* tgammaf overflow */
55 	    return (float)__kernel_standard((double)x,(double)x,140);
56 	}
57 	return y;
58 #endif
59 }
60 
61 #ifdef _DOUBLE_IS_32BITS
62 
63 #ifdef __STDC__
tgamma(double x)64 	double tgamma(double x)
65 #else
66 	double tgamma(x)
67 	double x;
68 #endif
69 {
70 	return (double) tgammaf((float) x);
71 }
72 
73 #endif /* defined(_DOUBLE_IS_32BITS) */
74