Skip to content

Commit 975beef

Browse files
author
Mikolaj Matalowski
committed
Move libphoenix math library implementation
Modify libphoenix Makefile, move libphoenix math library implementation, add definitions of float functions, decouple strtod.c from math library JIRA: RTOS-1132
1 parent b3a3023 commit 975beef

File tree

15 files changed

+231
-70
lines changed

15 files changed

+231
-70
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ include ctype/Makefile
4646
include err/Makefile
4747
include errno/Makefile
4848
include locale/Makefile
49-
include math/Makefile
5049
include misc/Makefile
5150
include net/Makefile
5251
include netinet/Makefile
@@ -65,6 +64,7 @@ include time/Makefile
6564
include unistd/Makefile
6665
include wchar/Makefile
6766
include ubsan/Makefile
67+
include libm/Makefile
6868

6969
#include test/Makefile
7070

@@ -82,7 +82,8 @@ install: install-headers install-libs
8282
install-headers: $(SRCHEADERS)
8383
@echo INSTALL "$(HEADERS_INSTALL_DIR)/*"; \
8484
mkdir -p "$(HEADERS_INSTALL_DIR)"; \
85-
cp -a include/* "$(HEADERS_INSTALL_DIR)";
85+
cp -a include/* "$(HEADERS_INSTALL_DIR)"; \
86+
cp -a libm/libmcs/libm/include/* "$(HEADERS_INSTALL_DIR)"
8687

8788
# TODO: remove `rm crt0.o` when we will be sure it's not a symlink to libphoenix.a anymore
8889
install-libs: $(LIB_TARGETS)

math/common.c renamed to libm/math/common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <float.h>
2020
#include "common.h"
2121

22-
2322
void normalizeSub(double *x, int *exp)
2423
{
2524
conv_t *conv = (conv_t *)x;
File renamed without changes.

libm/math/compatibility.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <math.h>
2+
3+
int __fpclassifyf(float x)
4+
{
5+
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x);
6+
}
7+
8+
9+
int __fpclassifyd(double x)
10+
{
11+
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x);
12+
}
13+
14+
const float __inff = __builtin_inff();
15+
const double __infd = __builtin_inf();
File renamed without changes.

math/exp.c renamed to libm/math/exp.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ double frexp(double x, int *exp)
4747
}
4848

4949

50+
float frexpf(float x, int *exp)
51+
{
52+
return (float)frexp((double)x, exp);
53+
}
54+
55+
5056
double ldexp(double x, int exp)
5157
{
5258
if (isnan(x) != 0) {
@@ -84,6 +90,12 @@ double ldexp(double x, int exp)
8490
}
8591

8692

93+
float ldexpf(float x, int exp)
94+
{
95+
return (float)ldexp((double)x, exp);
96+
}
97+
98+
8799
double log(double x)
88100
{
89101
double tmp, pow, res;
@@ -129,6 +141,12 @@ double log(double x)
129141
}
130142

131143

144+
float logf(float x)
145+
{
146+
return (float)log((double)x);
147+
}
148+
149+
132150
double log2(double x)
133151
{
134152
return (log(x) / M_LN2);
@@ -142,6 +160,12 @@ double log10(double x)
142160
}
143161

144162

163+
float log10f(float x)
164+
{
165+
return (float)log10((double)x);
166+
}
167+
168+
145169
double modf(double x, double *intpart)
146170
{
147171
conv_t *conv = (conv_t *)&x;
@@ -232,6 +256,12 @@ double exp(double x)
232256
}
233257

234258

259+
float expf(float x)
260+
{
261+
return (float)exp((double)x);
262+
}
263+
264+
235265
double ceil(double x)
236266
{
237267
#ifdef __IEEE754_CEIL
@@ -321,6 +351,12 @@ double fmod(double number, double denom)
321351
}
322352

323353

354+
float fmodf(float x, float y)
355+
{
356+
return (float)fmod((double)x, (double)y);
357+
}
358+
359+
324360
double round(double x)
325361
{
326362
#ifdef __IEEE754_ROUND

math/hyper.c renamed to libm/math/hyper.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ double cosh(double x)
4141
}
4242

4343

44+
float coshf(float x)
45+
{
46+
return (float)cosh((double)x);
47+
}
48+
49+
4450
double sinh(double x)
4551
{
4652
double y, f;
@@ -72,6 +78,12 @@ double sinh(double x)
7278
}
7379

7480

81+
float sinhf(float x)
82+
{
83+
return (double)sin((double)x);
84+
}
85+
86+
7587
double tanh(double x)
7688
{
7789
if (isnan(x) != 0) {
@@ -88,3 +100,9 @@ double tanh(double x)
88100
/* cosh is never equal to zero */
89101
return (sinh(x) / cosh(x));
90102
}
103+
104+
105+
float tanhf(float x)
106+
{
107+
return (float)tanh((double)x);
108+
}
File renamed without changes.
File renamed without changes.

include/math.h renamed to libm/math/include/math.h

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
#include <stdarg.h>
21-
#include <math/consts.h>
21+
#include <consts.h>
2222

2323

2424
#ifdef __cplusplus
@@ -60,126 +60,126 @@ extern "C" {
6060

6161

6262
/* Returns the cosine of an angle of x radians. */
63-
extern double cos(double x);
63+
double cos(double x);
6464

6565

6666
/* Returns the sine of an angle of x radians. */
67-
extern double sin(double x);
67+
double sin(double x);
6868

6969

7070
/* Returns the tangent of an angle of x radians. */
71-
extern double tan(double x);
71+
double tan(double x);
7272

7373

7474
/* Returns the principal value of the arc cosine of x, expressed in radians. */
75-
extern double acos(double x);
75+
double acos(double x);
7676

7777

7878
/* Returns the principal value of the arc sine of x, expressed in radians. */
79-
extern double asin(double x);
79+
double asin(double x);
8080

8181

8282
/* Returns the principal value of the arc tan of x, expressed in radians. */
83-
extern double atan(double x);
83+
double atan(double x);
8484

8585

8686
/* Returns the principal value of the arc tangent of y/x, expressed in radians. */
87-
extern double atan2(double y, double x);
87+
double atan2(double y, double x);
8888

8989

9090
/* Hyperbolic functions */
9191

9292

9393
/* Returns the hyperbolic cosine of x. */
94-
extern double cosh(double x);
94+
double cosh(double x);
9595

9696

9797
/* Returns the hyperbolic sine of x. */
98-
extern double sinh(double x);
98+
double sinh(double x);
9999

100100

101101
/* Returns the hyperbolic tangent of x. */
102-
extern double tanh(double x);
102+
double tanh(double x);
103103

104104

105105
/* Exponential and logarithmic functions */
106106

107107

108108
/* Returns the base-e exponential function of x, which is e raised to the power x: e^x. */
109-
extern double exp(double x);
109+
double exp(double x);
110110

111111

112112
/* Breaks the floating point number x into its binary significand
113113
* (a floating point with an absolute value between 0.5(included) and 1.0(excluded))
114114
* and an integral exponent for 2. */
115-
extern double frexp(double x, int *exp);
115+
double frexp(double x, int *exp);
116116

117117

118118
/* Returns the result of multiplying x (the significand) by 2 raised to the power of exp (the exponent). */
119-
extern double ldexp(double x, int exp);
119+
double ldexp(double x, int exp);
120120

121121

122122
/* Returns the natural logarithm of x. */
123-
extern double log(double x);
123+
double log(double x);
124124

125125

126126
/* Returns the common (base-2) logarithm of x. */
127-
extern double log2(double x);
127+
double log2(double x);
128128

129129

130130
/* Returns the common (base-10) logarithm of x. */
131-
extern double log10(double x);
131+
double log10(double x);
132132

133133

134134
/* Breaks x into an integral and a fractional part. */
135-
extern double modf(double x, double *intpart);
136-
extern float modff(float x, float *intpart);
135+
double modf(double x, double *intpart);
136+
float modff(float x, float *intpart);
137137

138138

139139
/* Power functions */
140140

141141

142142
/* Returns base raised to the power exponent. */
143-
extern double pow(double base, double exponent);
143+
double pow(double base, double exponent);
144144

145145

146146
/* Returns the square root of x. */
147-
extern double sqrt(double x);
147+
double sqrt(double x);
148148

149149

150150
/* Rounding and remainder functions */
151151

152152

153153
/* Rounds x upward, returning the smallest integral value that is not less than x. */
154-
extern double ceil(double x);
155-
extern float ceilf(float x);
154+
double ceil(double x);
155+
float ceilf(float x);
156156

157157

158158
/* Rounds x downward, returning the largest integral value that is not greater than x. */
159-
extern double floor(double x);
160-
extern float floorf(float x);
159+
double floor(double x);
160+
float floorf(float x);
161161

162162

163163
/* Returns the floating-point remainder of numer/denom (rounded towards zero). */
164-
extern double fmod(double numer, double denom);
164+
double fmod(double numer, double denom);
165165

166166

167167
/* Return the integral value nearest to x */
168-
extern double round(double x);
169-
extern float roundf(float x);
168+
double round(double x);
169+
float roundf(float x);
170170

171171

172172
/* Rounds x toward zero, returning the nearest integral value that is not larger in magnitude than x. */
173-
extern double trunc(double x);
174-
extern float truncf(float x);
173+
double trunc(double x);
174+
float truncf(float x);
175175

176176

177177
/* Miscellaneous */
178178

179179

180180
/* Returns the absolute value of x: |x|. */
181-
extern double fabs(double x);
182-
extern float fabsf(float x);
181+
double fabs(double x);
182+
float fabsf(float x);
183183

184184

185185
/* C99 extensions */
@@ -203,25 +203,6 @@ float sqrtf(float x);
203203
float fmodf(float num, float denom);
204204

205205

206-
#define cosf(x) ((float)cos(x))
207-
#define sinf(x) ((float)sin(x))
208-
#define tanf(x) ((float)tan(x))
209-
#define acosf(x) ((float)acos(x))
210-
#define asinf(x) ((float)asin(x))
211-
#define atanf(x) ((float)atan(x))
212-
#define atan2f(y, x) ((float)atan2(y, x))
213-
#define coshf(x) ((float)cosh(x))
214-
#define sinhf(x) ((float)sinh(x))
215-
#define tanhf(x) ((float)tanh(x))
216-
#define expf(x) ((float)exp(x))
217-
#define frexpf(x, exp) ((float)frexp(x, exp))
218-
#define ldexpf(x, exp) ((float)ldexp(x, exp))
219-
#define logf(x) ((float)log(x))
220-
#define log10f(x) ((float)log10(x))
221-
#define powf(base, exponent) ((float)pow(base, exponent))
222-
#define fmodf(num, denom) ((float)fmod(num, denom))
223-
224-
225206
#ifdef __cplusplus
226207
}
227208
#endif

0 commit comments

Comments
 (0)