Skip to content

Commit 4b82015

Browse files
authored
Spe math fixes (#379)
* Wrong Printf version requirement printing * Set null to inf when exiting from thread * Fix on pthread_get_specific if called from main thread * Fixed critical (and minor) bugs in pthread library. At moment all test program seems to work correctly * Some fixes for libresolv. Added DNS cache to requests * Some fixes for libresolv. Added DNS cache to requests * stdlib: fix multiple bugs and correctness issues * stdio: fix buffer overwrite, error handling, and overflow issues * posix: fix critical bugs in IPC, signals, mmap, and statvfs * socket: fix multiple bugs found * Fix multiple bugs across clib4 library * math: fixed 8 bugs (2 general + 6 SPE-specific)
1 parent dab73a1 commit 4b82015

File tree

8 files changed

+15
-20
lines changed

8 files changed

+15
-20
lines changed

library/c.lib_rev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define REVISION 1
33
#define SUBREVISION 0
44

5-
#define DATE "06.03.2026"
5+
#define DATE "09.03.2026"
66
#define VERS "clib4.library 2.1"
7-
#define VSTRING "clib4.library 2.1 (06.03.2026)\r\n"
8-
#define VERSTAG "\0$VER: clib4.library 2.1-ab40f98 (06.03.2026)"
7+
#define VSTRING "clib4.library 2.1 (09.03.2026)\r\n"
8+
#define VERSTAG "\0$VER: clib4.library 2.1-ab40f98 (09.03.2026)"

library/math/e_sqrt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ static const float one = 1.0, tiny = 1.0e-30;
1111
double
1212
__ieee754_sqrt(double x) {
1313
double z;
14-
15-
#ifndef __SPE__
1614
int32_t sign = (int32_t) 0x80000000;
1715
int32_t ix0, s0, q, m, t, i;
1816
uint32_t r, t1, s1, ix1, q1;
@@ -109,6 +107,5 @@ __ieee754_sqrt(double x) {
109107
if ((q & 1) == 1) ix1 |= sign;
110108
ix0 += (m << 20);
111109
INSERT_WORDS(z, ix0, ix1);
112-
#endif
113110
return z;
114111
}

library/math/fpsetmask.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ fpsetmask(fp_except_t mask) {
1919
return (old);
2020
#else
2121
uint32_t fpscr;
22-
fp_rnd_t old;
22+
fp_except_t old;
2323

2424
__asm__ __volatile("mfspr %0, %1" : "=r"(fpscr) : "K"(SPR_SPEFSCR));
25-
old = (fp_rnd_t)((fpscr >> 3) & 0x1f);
25+
old = (fp_except_t)((fpscr >> 3) & 0x1f);
2626
fpscr = (fpscr & 0xffffff07) | (mask << 3);
2727
__asm__ __volatile("mtspr %1,%0" :: "r"(fpscr), "K"(SPR_SPEFSCR));
2828
return (old);

library/math/s_fpclassify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ __fpclassify_double(double d) {
7171
/* Both exponent and fraction are zero -> zero */
7272
result = FP_ZERO;
7373
}
74-
else if ((x.raw[0] & 0x7fff0000) == 0) {
74+
else if ((x.raw[0] & 0x7ff00000) == 0) {
7575
SHOWMSG("subnormal");
7676

7777
/* Exponent = 0 -> subnormal (IEEE 754) */

library/math/s_isinf.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ __isinf(double d) {
2020
#else
2121
union ieee_double x;
2222

23-
/* Exponent = 2047 and fraction = 0.0 -> infinity */
24-
x.raw[0] = 0x7ff00000;
25-
x.raw[1] = 0x00000000;
23+
x.value = d;
2624

27-
return(x.value);
25+
/* Exponent = 2047 and fraction = 0.0 -> infinity */
26+
return (((x.raw[0] & 0x7fffffff) == 0x7ff00000) && (x.raw[1] == 0));
2827
#endif
2928
}
3029

@@ -39,7 +38,7 @@ __isinff(float f) {
3938
int32_t ix;
4039
GET_FLOAT_WORD(ix, f);
4140
ix &= 0x7fffffff;
42-
return FLT_UWORD_IS_NAN(ix);
41+
return (ix == 0x7f800000);
4342
#endif
4443
}
4544

library/math/s_isnan.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ __isnan(double d) {
1616
#else
1717
union ieee_double x;
1818

19-
/* Exponent = 2047 and fraction != 0.0; this must be a quiet nan. */
20-
x.raw[0] = 0x7ff80000;
21-
x.raw[1] = 0x00000001;
19+
x.value = d;
2220

23-
return x.value;
21+
/* Exponent = 2047 and fraction != 0.0 -> NaN */
22+
return (((x.raw[0] & 0x7ff00000) == 0x7ff00000) && ((x.raw[0] & 0x000fffff) != 0 || (x.raw[1] != 0)));
2423
#endif
2524
}
2625

library/math/s_ldexp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ldexp(double x, int exp) {
1515
} else {
1616
result = scalbn(x, exp);
1717

18-
if (isinf(result) || (result < DBL_MIN || result > -DBL_MIN))
18+
if (isinf(result) || (result < DBL_MIN && result > -DBL_MIN))
1919
__set_errno(ERANGE);
2020
}
2121

library/math/s_ldexpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ldexpf(float x, int exp) {
1515
} else {
1616
result = scalbnf(x, exp);
1717

18-
if (isinf(result) || (result < FLT_MIN || result > -FLT_MIN))
18+
if (isinf(result) || (result < FLT_MIN && result > -FLT_MIN))
1919
__set_errno(ERANGE);
2020
}
2121

0 commit comments

Comments
 (0)