Skip to content

Commit 7fb3907

Browse files
ZERICO2005adriweb
authored andcommitted
Fixed formatting and indentation in math.h functions, corrected softfloat linker.mk, fixed lgammaf softlock bug, fixed erfcf/erfcl for negative inputs, and fixed the zilog copyright headers so I can sleep peacefully
1 parent cff7ecd commit 7fb3907

31 files changed

+614
-566
lines changed

src/libc/asinf.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55
* arctan is called after appropriate range reduction.
66
*/
77

8-
#include <errno.h>
9-
#include <math.h>
8+
#include <errno.h>
9+
#include <math.h>
1010

1111
#define pio2 1.57079632679490
1212

1313
float _asinf_c(float arg) {
14-
float sign, temp;
15-
16-
sign = 1.;
17-
if(arg < 0) {
18-
arg = -arg;
19-
sign = -1.;
20-
}
21-
22-
if(arg > 1.) {
23-
errno = EDOM;
24-
return(0.);
25-
}
26-
27-
temp = sqrt(1. - arg*arg);
28-
if(arg > 0.7) {
29-
temp = pio2 - atan(temp/arg);
30-
} else {
31-
temp = atan(arg/temp);
32-
}
33-
34-
return(sign*temp);
14+
float sign, temp;
15+
16+
sign = 1.;
17+
if(arg < 0) {
18+
arg = -arg;
19+
sign = -1.;
20+
}
21+
22+
if(arg > 1.) {
23+
errno = EDOM;
24+
return(0.);
25+
}
26+
27+
temp = sqrtf(1. - arg*arg);
28+
if(arg > 0.7) {
29+
temp = pio2 - atanf(temp/arg);
30+
} else {
31+
temp = atanf(arg/temp);
32+
}
33+
34+
return(sign*temp);
3535
}
3636

3737
double _asin_c(double) __attribute__((alias("_asinf_c")));

src/libc/atan2f.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
/* Copyright (c) 2000-2008 Zilog, Inc. */
22
#include <math.h>
33

4-
#define pio2 1.57079632679489e0
4+
#define pio2 1.57079632679489e0
55

66
float _atan2f_c(float arg1,float arg2) {
7-
float satan(float);
7+
float satan(float);
88

9-
if((arg1+arg2)==arg1) {
10-
if(arg1 >= 0.) {
11-
return(pio2);
12-
} else {
13-
return(-pio2);
14-
}
15-
} else if(arg2 < 0.) {
16-
if(arg1 >= 0.) {
17-
return(pio2+pio2 - satan(-arg1/arg2));
18-
} else {
19-
return(-pio2-pio2 + satan(arg1/arg2));
20-
}
21-
} else if(arg1 > 0) {
22-
return(satan(arg1/arg2));
23-
} else {
24-
return(-satan(-arg1/arg2));
25-
}
9+
if((arg1+arg2)==arg1) {
10+
if(arg1 >= 0.) {
11+
return(pio2);
12+
} else {
13+
return(-pio2);
14+
}
15+
} else if(arg2 < 0.) {
16+
if(arg1 >= 0.) {
17+
return(pio2+pio2 - satan(-arg1/arg2));
18+
} else {
19+
return(-pio2-pio2 + satan(arg1/arg2));
20+
}
21+
} else if(arg1 > 0) {
22+
return(satan(arg1/arg2));
23+
} else {
24+
return(-satan(-arg1/arg2));
25+
}
2626
}
2727

2828
double _atan2_c(double, double) __attribute__((alias("_atan2f_c")));

src/libc/atanf.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@
1515
*/
1616
#include <math.h>
1717

18-
#define sq2p1 2.41421356237309e0
19-
#define sq2m1 0.414213562373095e0
20-
#define pio2 1.57079632679489e0
21-
#define pio4 0.785398163397448e0
22-
#define p4 0.161536412982230e2
23-
#define p3 0.268425481955040e3
24-
#define p2 0.115302935154049e4
25-
#define p1 0.178040631643320e4
26-
#define p0 0.896785974036639e3
27-
#define q4 0.589569705084446e2
28-
#define q3 0.536265374031215e3
29-
#define q2 0.166678381488163e4
30-
#define q1 0.207933497444541e4
31-
#define q0 0.896785974036639e3
18+
#define sq2p1 2.41421356237309e0
19+
#define sq2m1 0.414213562373095e0
20+
#define pio2 1.57079632679489e0
21+
#define pio4 0.785398163397448e0
22+
#define p4 0.161536412982230e2
23+
#define p3 0.268425481955040e3
24+
#define p2 0.115302935154049e4
25+
#define p1 0.178040631643320e4
26+
#define p0 0.896785974036639e3
27+
#define q4 0.589569705084446e2
28+
#define q3 0.536265374031215e3
29+
#define q2 0.166678381488163e4
30+
#define q1 0.207933497444541e4
31+
#define q0 0.896785974036639e3
3232

3333
/**
3434
* atan makes its argument positive and
3535
* calls the inner routine satan.
3636
*/
3737

3838
float _atanf_c(float arg) {
39-
float satan(float);
39+
float satan(float);
4040

41-
if(arg>0) {
42-
return(satan(arg));
43-
} else {
44-
return(-satan(-arg));
45-
}
41+
if(arg>0) {
42+
return(satan(arg));
43+
} else {
44+
return(-satan(-arg));
45+
}
4646
}
4747

4848
double _atan_c(double) __attribute__((alias("_atanf_c")));
@@ -59,13 +59,13 @@ double _atan_c(double) __attribute__((alias("_atanf_c")));
5959
*/
6060

6161
static float xatan(float arg) {
62-
float argsq;
63-
float value;
62+
float argsq;
63+
float value;
6464

65-
argsq = arg*arg;
66-
value = ((((p4*argsq + p3)*argsq + p2)*argsq + p1)*argsq + p0);
67-
value = value/(((((argsq + q4)*argsq + q3)*argsq + q2)*argsq + q1)*argsq + q0);
68-
return(value*arg);
65+
argsq = arg*arg;
66+
value = ((((p4*argsq + p3)*argsq + p2)*argsq + p1)*argsq + p0);
67+
value = value/(((((argsq + q4)*argsq + q3)*argsq + q2)*argsq + q1)*argsq + q0);
68+
return(value*arg);
6969
}
7070

7171
/**
@@ -74,11 +74,11 @@ static float xatan(float arg) {
7474
*/
7575

7676
float satan(float arg) {
77-
if(arg < sq2m1) {
78-
return(xatan(arg));
79-
} else if(arg > sq2p1) {
80-
return(pio2 - xatan(1.0/arg));
81-
} else {
82-
return(pio4 + xatan((arg-1.0)/(arg+1.0)));
83-
}
77+
if(arg < sq2m1) {
78+
return(xatan(arg));
79+
} else if(arg > sq2p1) {
80+
return(pio2 - xatan(1.0/arg));
81+
} else {
82+
return(pio4 + xatan((arg-1.0)/(arg+1.0)));
83+
}
8484
}

src/libc/atanhl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
long double atanhl(long double x)
44
{
5-
return .5l * logl((1 + x) / (1 - x));
5+
return .5L * logl((1 + x) / (1 - x));
66
}

src/libc/bsearch.c

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/************************************************************************/
2-
/* */
3-
/* Copyright (C)1987-2008 by */
4-
/* Zilog, Inc. */
5-
/* */
6-
/* San Jose, California */
7-
/* */
2+
/* */
3+
/* Copyright (C)1987-2008 by */
4+
/* Zilog, Inc. */
5+
/* */
6+
/* San Jose, California */
7+
/* */
88
/************************************************************************/
9+
910
#include <stddef.h>
1011
#include <stdlib.h>
1112

@@ -14,62 +15,63 @@
1415
* bsearch - binary search
1516
*
1617
* Inputs:
17-
* key - key to search for
18-
* base - base of array to be sorted
19-
* num - number of elements
20-
* width - size of each element
21-
* comp - pointer to function for comparison
18+
* key - key to search for
19+
* base - base of array to be sorted
20+
* num - number of elements
21+
* width - size of each element
22+
* comp - pointer to function for comparison
2223
*
2324
* Returns:
24-
* nothing
25+
* nothing
2526
*
2627
*************************************************/
27-
void *bsearch(void *keyp, void *ptr, size_t num, size_t width,
28-
int (*comp)(const void *, const void *))
29-
{
30-
char *key = keyp;
31-
char *base = ptr;
32-
unsigned int mid;
33-
unsigned int low;
34-
unsigned int high;
35-
int d;
36-
unsigned int pmid;
37-
char *addr;
28+
void *bsearch(
29+
void *keyp, void *ptr, size_t num, size_t width,
30+
int (*comp)(const void *, const void *)
31+
) {
32+
char *key = keyp;
33+
char *base = ptr;
34+
unsigned int mid;
35+
unsigned int low;
36+
unsigned int high;
37+
int d;
38+
unsigned int pmid;
39+
char *addr;
3840

39-
/* make high the nearest power of two for */
40-
/* efficiency and to ensure we always */
41-
/* terminate properly. */
42-
/* Note that high is always higher */
43-
/* than it should be so that we will */
44-
/* not fail to find the last entry in the */
45-
/* table. */
41+
/* make high the nearest power of two for */
42+
/* efficiency and to ensure we always */
43+
/* terminate properly. */
44+
/* Note that high is always higher */
45+
/* than it should be so that we will */
46+
/* not fail to find the last entry in the */
47+
/* table. */
4648

47-
high = 0x0001;
48-
while (high <= num)
49-
high <<= 1;
50-
low = 0;
51-
mid = 0;
49+
high = 0x0001;
50+
while (high <= num)
51+
high <<= 1;
52+
low = 0;
53+
mid = 0;
5254

53-
/* begin the search */
55+
/* begin the search */
5456

55-
for(;;) {
56-
pmid = mid;
57-
mid = ((high - low) >> 1) + low;
57+
for(;;) {
58+
pmid = mid;
59+
mid = ((high - low) >> 1) + low;
5860

59-
if (pmid == mid) /* terminate because we're */
60-
return(NULL); /* oscilating. */
61+
if (pmid == mid) /* terminate because we're */
62+
return(NULL); /* oscilating. */
6163

62-
if (mid >= num) { /* we're above the array. */
63-
high = mid; /* pretend element is larger*/
64-
continue; /* than the key. */
65-
}
64+
if (mid >= num) { /* we're above the array. */
65+
high = mid; /* pretend element is larger*/
66+
continue; /* than the key. */
67+
}
6668

67-
d = (*comp)(key,addr = base + mid * width);
68-
if (d == 0) /* we found it */
69-
return(addr);
70-
if (d < 0) /* key is less than mid, */
71-
high = mid; /* set high to mid. */
72-
else /* key is greater than mid, */
73-
low = mid; /* set low to mid. */
74-
}
69+
d = (*comp)(key,addr = base + mid * width);
70+
if (d == 0) /* we found it */
71+
return(addr);
72+
if (d < 0) /* key is less than mid, */
73+
high = mid; /* set high to mid. */
74+
else /* key is greater than mid, */
75+
low = mid; /* set low to mid. */
76+
}
7577
}

0 commit comments

Comments
 (0)