Skip to content

Commit f01fe65

Browse files
committed
version V1_214_1. See README for details
1 parent 3a0adb6 commit f01fe65

File tree

141 files changed

+4037
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+4037
-67
lines changed

Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ C_LIB = \
280280
stdlib_udivsi4.o \
281281
stdlib_umodsi3.o \
282282
stdlib_unsetenv.o \
283+
stdlib_ctzsi2.o \
284+
stdlib_clzsi2.o \
283285
strings_ffs.o \
284286
strings_strcasecmp.o \
285287
strings_strncasecmp.o \
@@ -566,8 +568,6 @@ MATH_LIB = \
566568
math_hypotf.o \
567569
math_ilogb.o \
568570
math_ilogbf.o \
569-
math_inf.o \
570-
math_inff.o \
571571
math_init_exit.o \
572572
math_isfinite.o \
573573
math_isunordered.o \
@@ -597,6 +597,8 @@ MATH_LIB = \
597597
math_modff.o \
598598
math_nan.o \
599599
math_nanf.o \
600+
math_inf.o \
601+
math_inff.o \
600602
math_nearbyint.o \
601603
math_nearbyintf.o \
602604
math_nextafter.o \
@@ -695,7 +697,9 @@ MATH_LIB_IEEE = \
695697
math_floatunsidf.o \
696698
math_divdi3.o \
697699
math_moddi3.o \
698-
math_muldi3.o
700+
math_muldi3.o \
701+
math_ashldi3.o \
702+
math_lshrdi3.o
699703

700704
NET_LIB = \
701705
net.lib_rev.o \
@@ -776,7 +780,8 @@ NET_LIB = \
776780
usergroup_setreuid.o \
777781
usergroup_setsid.o \
778782
usergroup_setuid.o \
779-
utsname_uname.o
783+
utsname_uname.o \
784+
socket_getaddrinfo.o
780785

781786
DEBUG_LIB = \
782787
debug.lib_rev.o \
@@ -976,7 +981,7 @@ $(OUT).elf: libs/libc.a libs/libunix.a libs/libm.a libs/libm881.a libs/libnet.a
976981
clean:
977982
$(info Cleaning...)
978983
ifdef WINDOWS
979-
@del /q obj\* out\*
984+
@del /q obj\* obj\libamiga_objs\* obj\libc_objs\* obj\libdebug_objs\* obj\libdebug_objs\* obj\libm881_objs\* obj\libnet_objs\* obj\libunix_objs\* out\* libs\*
980985
else
981986
@$(RM) obj/* out/*
982987
endif
@@ -985,7 +990,7 @@ endif
985990

986991
$(c_clib_objects) :$(LIBC_OBJS)/%.o : %.c
987992
$(info Compiling $<)
988-
@$(CC) $(CCFLAGS) -c -o $@ $(CURDIR)/$<
993+
@$(CC) $(CCFLAGS) -DIEEE_FLOATING_POINT_SUPPORT -c -o $@ $(CURDIR)/$<
989994

990995
$(c_unixlib_objects) : $(LIBUNIX_OBJS)/%.o : %.c
991996
$(info Compiling $<)

README.md

+20-16
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ The below functions are provided:
4545
[vsprintf](https://man7.org/linux/man-pages/man3/vsprintf.3.html), [vsscanf](https://man7.org/linux/man-pages/man3/vsscanf.3.html), [vscanf](https://man7.org/linux/man-pages/man3/vscanf.3.html),
4646
[abort](https://man7.org/linux/man-pages/man3/abort.3.html), [abs](https://man7.org/linux/man-pages/man3/abs.3.html), [alloca](https://man7.org/linux/man-pages/man3/alloca.3.html),
4747
[atexit](https://man7.org/linux/man-pages/man3/atexit.3.html), [atoi](https://man7.org/linux/man-pages/man3/atoi.3.html), [atol](https://man7.org/linux/man-pages/man3/atol.3.html),
48-
[bsearch](https://man7.org/linux/man-pages/man3/bsearch.3.html), [calloc](https://man7.org/linux/man-pages/man3/calloc.3.html), [div](https://man7.org/linux/man-pages/man3/div.3.html),
48+
[bsearch](https://man7.org/linux/man-pages/man3/bsearch.3.html), [calloc](https://man7.org/linux/man-pages/man3/calloc.3.html),
49+
[__clzsi2](https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html), [__ctzsi2](https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html), [div](https://man7.org/linux/man-pages/man3/div.3.html),
4950
[__divsi3](https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html), [exit](https://man7.org/linux/man-pages/man3/exit.3.html),
5051
[free](https://man7.org/linux/man-pages/man3/free.3.html), [getenv](https://man7.org/linux/man-pages/man3/getenv.3.html), [labs](https://man7.org/linux/man-pages/man3/labs.3.html),
5152
[llabs](https://man7.org/linux/man-pages/man3/llabs.3.html), [ldiv](https://man7.org/linux/man-pages/man3/ldiv.3.html), [malloc](https://man7.org/linux/man-pages/man3/malloc.3.html),
@@ -158,7 +159,8 @@ The below functions are provided:
158159
[vscanf](https://man7.org/linux/man-pages/man3/vscanf.3.html), [vprintf](https://man7.org/linux/man-pages/man3/vprintf.3.html), [vsnprintf](https://man7.org/linux/man-pages/man3/vsnprintf.3.html),
159160
[vsprintf](https://man7.org/linux/man-pages/man3/vsprintf.3.html), [atof](https://man7.org/linux/man-pages/man3/atof.3.html), [strtod](https://man7.org/linux/man-pages/man3/strtod.3.html),
160161
[strtof](https://man7.org/linux/man-pages/man3/strtof.3.html), [difftime](https://man7.org/linux/man-pages/man3/difftime.3.html),
161-
[__adddf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__addsf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__divdf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html),
162+
[__adddf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__addsf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html),
163+
[__ashldi3](https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html),[__divdf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html),
162164
[__divsf3](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__eqdf2](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__eqsf2](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html),
163165
[__extendsfdf2](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__fixdfsi](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__fixsfsi](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html),
164166
[__fixunsdfsi](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__fixunssfsi](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html), [__floatsidf](https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html),
@@ -202,7 +204,8 @@ The below functions are provided:
202204
[log1p](https://man7.org/linux/man-pages/man3/log1p.3.html), [log1pf](https://man7.org/linux/man-pages/man3/log1pf.3.html), [log2](https://man7.org/linux/man-pages/man3/log2.3.html),
203205
[log2f](https://man7.org/linux/man-pages/man3/log2f.3.html), [logb](https://man7.org/linux/man-pages/man3/logb.3.html), [logbf](https://man7.org/linux/man-pages/man3/logbf.3.html),
204206
[logf](https://man7.org/linux/man-pages/man3/logf.3.html), [lrint](https://man7.org/linux/man-pages/man3/lrint.3.html), [lrintf](https://man7.org/linux/man-pages/man3/lrintf.3.html),
205-
[lround](https://man7.org/linux/man-pages/man3/lround.3.html), [lroundf](https://man7.org/linux/man-pages/man3/lroundf.3.html), [modf](https://man7.org/linux/man-pages/man3/modf.3.html),
207+
[lround](https://man7.org/linux/man-pages/man3/lround.3.html), [lroundf](https://man7.org/linux/man-pages/man3/lroundf.3.html),
208+
[__lshrdi3](https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html), [modf](https://man7.org/linux/man-pages/man3/modf.3.html),
206209
[modff](https://man7.org/linux/man-pages/man3/modff.3.html), [nan](https://man7.org/linux/man-pages/man3/nan.3.html), [nanf](https://man7.org/linux/man-pages/man3/nanf.3.html),
207210
[nearbyint](https://man7.org/linux/man-pages/man3/nearbyint.3.html), [nearbyintf](https://man7.org/linux/man-pages/man3/nearbyintf.3.html), [nextafter](https://man7.org/linux/man-pages/man3/nextafter.3.html),
208211
[nextafterf](https://man7.org/linux/man-pages/man3/nextafterf.3.html), [pow](https://man7.org/linux/man-pages/man3/pow.3.html) [powf](https://man7.org/linux/man-pages/man3/powf.3.html),
@@ -222,7 +225,8 @@ The below functions are provided:
222225
[vsprintf](https://man7.org/linux/man-pages/man3/vsprintf.3.html), [atof](https://man7.org/linux/man-pages/man3/atof.3.html), [strtod](https://man7.org/linux/man-pages/man3/strtod.3.html),
223226
[strtof](https://man7.org/linux/man-pages/man3/strtof.3.html), [difftime](https://man7.org/linux/man-pages/man3/difftime.3.html)
224227
- In `libnet`: [accept](https://man7.org/linux/man-pages/man2/accept.2.html), [bind](https://man7.org/linux/man-pages/man2/bind.2.html), [connect](https://man7.org/linux/man-pages/man2/connect.2.html),
225-
[gethostbyaddr](https://man7.org/linux/man-pages/man3/gethostbyaddr.3.html), [gethostbyname](https://man7.org/linux/man-pages/man3/gethostbyname.3.html), [gethostid](https://man7.org/linux/man-pages/man3/gethostid.3.html),
228+
[getaddrinfo](https://man7.org/linux/man-pages/man3/getaddrinfo.3.html), [gethostbyaddr](https://man7.org/linux/man-pages/man3/gethostbyaddr.3.html),
229+
[gethostbyname](https://man7.org/linux/man-pages/man3/gethostbyname.3.html), [gethostid](https://man7.org/linux/man-pages/man3/gethostid.3.html),
226230
[gethostname](https://man7.org/linux/man-pages/man2/gethostname.2.html), [getnetbyaddr](https://man7.org/linux/man-pages/man3/getnetbyaddr.3.html), [getnetbyname](https://man7.org/linux/man-pages/man3/getnetbyname.3.html),
227231
[getpeername](https://man7.org/linux/man-pages/man2/getpeername.2.html), [getprotobyname](https://man7.org/linux/man-pages/man3/getprotobyname.3.html), [getprotobynumber](https://man7.org/linux/man-pages/man3/getprotobynumber.3.html),
228232
[getservbyname](https://man7.org/linux/man-pages/man3/getservbyname.3.html), [getservbyport](https://man7.org/linux/man-pages/man3/getservbyport.3.html), [getsockname](https://man7.org/linux/man-pages/man2/getsockname.2.html),
@@ -290,18 +294,7 @@ f. At the end, close the UAE window\
290294
<u>Note</u>: after the test, UAE may signal a (false) read error on the Workench disk. This is due to the fact that we modified its configuration while running
291295
- `libunix` should be tested after you changed the definition of the static libs order in the `Makefile` to put -lunix before -lc (see the commented static_libs lines in the `Makefile` and don't forget to put back the original lines after the test!)
292296

293-
If you want to use the libraries in your own project, your code will have to follow the skeleton of the included `main.c` file:
294-
- Check for the Workbench startup message
295-
- Assign to the variable __WBenchMsg the value of the pointer to the Workbench startup message, or assign NULL if started from command line
296-
- Set __exit_blocked to FALSE to push exit() and similar functions to longjmp to target set by setjmp()
297-
- Declare and open the following libraries: Exec, intuition.library, dos.library, utility.library, graphics.library, commodities.library and icon.library
298-
- Assign to the variable __UtilityBase the value of UtilityBase
299-
- Set the target `out:` (which is used by `exit`) through the `setjmp` instruction
300-
- Call all the constructors, like in the `fcntCallCtor` function (the constructors must be called in a specific order)\
301-
At the end:
302-
- At the `out:` target, call the destructors, like in the `fcntCallDtor` function (the destructors must also be called in a specific order)
303-
- Close all libraries
304-
- If needed, reply to the Workbench startup message
297+
If you want to use the libraries in your own project, your code will have to follow the skeleton of the included `main.c` file.
305298

306299
It is also mandatory:
307300
- To declare the static libs in your `Makefile`:\
@@ -327,10 +320,21 @@ b. static_libs := -lm -ldebug -lnet -lunix -lc -lamiga, to use UNIX style paths
327320
### V1_214
328321
- First version
329322

323+
### V1_214_1
324+
- Better support of inf and NaN by math functions
325+
- Added functions __ashldi3, __lshrdi3, getaddrinfo, __clzsi2 and __ctzsi2
326+
- __time_delay made reentrant
327+
- Clean in Makefile improved
328+
- clib compiled to handle floats
329+
- Fixed code in main to distinguish correctly between start from CLI or Workbench
330+
- atan2 fixed
331+
330332
## Additional credits
331333

332334
- Main code is coming from [clib2](https://github.com/adtools/clib2) written by Olaf Barthel.
333335

334336
- Code for ffp is coming from [MotoFFP](https://github.com/bayerf42/MotoFFP) and [Le_Lisp](https://github.com/GunterMueller/Le_Lisp/).
335337

338+
- Code for getaddrinfo is coming from DNS Tracer
339+
336340
- Remaining code (additional functions, adaptations, wrappers) by [JOB](https://github.com/jyoberle).

library/math_acos.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ __acos(double x)
204204

205205
/****************************************************************************/
206206

207+
// For finite values of x not in the range [-1,1], a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned.
208+
// If x is NaN, a NaN shall be returned.
209+
// If x is ±Inf, a domain error shall occur, and a NaN shall be returned.
207210
double
208211
acos(double x)
209212
{
@@ -215,7 +218,8 @@ acos(double x)
215218
}
216219
else
217220
{
218-
result = 0;
221+
// result = 0;
222+
result = nan(NULL); // return nan to be consistent with acosf
219223
__set_errno(EDOM);
220224
}
221225

library/math_acosf.c

+5
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ qS2 = 2.0209457874e+00, /* 0x4001572d */
6969
qS3 = -6.8828397989e-01, /* 0xbf303361 */
7070
qS4 = 7.7038154006e-02; /* 0x3d9dc62e */
7171

72+
// For finite values of x not in the range [-1,1], a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned.
73+
// If x is NaN, a NaN shall be returned.
74+
// If x is ±Inf, a domain error shall occur, and a NaN shall be returned.
7275
float
7376
acosf(float x)
7477
{
7578
float z,p,q,r,w,s,c,df;
7679
LONG hx,ix;
80+
7781
GET_FLOAT_WORD(hx,x);
7882
ix = hx&0x7fffffff;
83+
7984
if(ix==0x3f800000) { /* |x|==1 */
8085
if(hx>0) return 0.0; /* acos(1) = 0 */
8186
else return pi+(float)2.0*pio2_lo; /* acos(-1)= pi */

library/math_acosh.c

+5
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ static const double
5454
one = 1.0,
5555
ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
5656

57+
// For finite values of x < 1, a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned.
58+
// If x is NaN, a NaN shall be returned.
59+
// If x is +Inf, +Inf shall be returned
60+
// If x is -Inf, a domain error shall occur, and a NaN shall be returned.
5761
double
5862
acosh(double x)
5963
{
6064
double t;
6165
LONG hx;
6266
ULONG lx;
67+
6368
EXTRACT_WORDS(hx,lx,x);
6469
if(hx<0x3ff00000) { /* x < 1 */
6570
return (x-x)/(x-x);

library/math_acoshf.c

+5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ static const float
5757
one = 1.0,
5858
ln2 = 6.9314718246e-01; /* 0x3f317218 */
5959

60+
// For finite values of x < 1, a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned.
61+
// If x is NaN, a NaN shall be returned.
62+
// If x is +Inf, +Inf shall be returned
63+
// If x is -Inf, a domain error shall occur, and a NaN shall be returned.
6064
float
6165
acoshf(float x)
6266
{
6367
float t;
6468
LONG hx;
69+
6570
GET_FLOAT_WORD(hx,x);
6671
if(hx<0x3f800000) { /* x < 1 */
6772
return (x-x)/(x-x);

library/math_adddf3.c

+44
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,50 @@ extern struct Library *MathIeeeDoubBasBase;
5656

5757
__attribute__((externally_visible)) double __adddf3(double a,double b)
5858
{
59+
if(isnan(a) || isnan(b))
60+
return(nan(NULL));
61+
62+
if(isinf(a) && isinf(b))
63+
{
64+
if(signbit(a) == 0)
65+
{
66+
if(signbit(b) == 0)
67+
return(__inf()); // +infinity
68+
69+
// b is -infinity
70+
__set_errno(EDOM);
71+
return(nan(NULL));
72+
}
73+
74+
// a is -infinity
75+
if(signbit(b) == 0)
76+
{
77+
__set_errno(EDOM);
78+
return(nan(NULL));
79+
}
80+
81+
// b is -infinity
82+
return(-__inf()); // -infinity
83+
}
84+
85+
if(isinf(a))
86+
{
87+
if(signbit(a) == 0)
88+
return(__inf());
89+
90+
// a is -infinity
91+
return(-__inf());
92+
}
93+
94+
if(isinf(b))
95+
{
96+
if(signbit(b) == 0)
97+
return(__inf());
98+
99+
// b is -infinity
100+
return(-__inf());
101+
}
102+
59103
return(IEEEDPAdd(a,b));
60104
}
61105

library/math_addsf3.c

+44
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,50 @@ __addsf3(float x,float y)
4646
{
4747
float result;
4848

49+
if(isnan(x) || isnan(y))
50+
return(nanf(NULL));
51+
52+
if(isinf(x) && isinf(y))
53+
{
54+
if(signbit(x) == 0)
55+
{
56+
if(signbit(y) == 0)
57+
return(__inff()); // +infinity
58+
59+
// y is -infinity
60+
__set_errno(EDOM);
61+
return(nanf(NULL));
62+
}
63+
64+
// x is -infinity
65+
if(signbit(y) == 0)
66+
{
67+
__set_errno(EDOM);
68+
return(nanf(NULL));
69+
}
70+
71+
// y is -infinity
72+
return(-__inff()); // -infinity
73+
}
74+
75+
if(isinf(x))
76+
{
77+
if(signbit(x)== 0)
78+
return(__inff());
79+
80+
// x is -infinity
81+
return(-__inff());
82+
}
83+
84+
if(isinf(y))
85+
{
86+
if(signbit(y) == 0)
87+
return(__inff());
88+
89+
// y is -infinity
90+
return(-__inff());
91+
}
92+
4993
result = IEEESPAdd(x,y);
5094

5195
return(result);

library/math_asin.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ __asin(double x)
215215

216216
/****************************************************************************/
217217

218+
// For finite values of x not in the range [-1,1], a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned.
219+
// If x is NaN, a NaN shall be returned.
220+
// If x is ±Inf, a domain error shall occur, and a NaN shall be returned.
218221
double
219222
asin(double x)
220223
{
@@ -226,7 +229,8 @@ asin(double x)
226229
}
227230
else
228231
{
229-
result = 0;
232+
// result = 0;
233+
result = nan(NULL); // return nan to be consistent with asinf
230234
__set_errno(EDOM);
231235
}
232236

library/math_asinf.c

+4
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ qS2 = 2.0209457874e+00, /* 0x4001572d */
7171
qS3 = -6.8828397989e-01, /* 0xbf303361 */
7272
qS4 = 7.7038154006e-02; /* 0x3d9dc62e */
7373

74+
// For finite values of x not in the range [-1,1], a domain error shall occur, and either a NaN (if supported), or an implementation-defined value shall be returned.
75+
// If x is NaN, a NaN shall be returned.
76+
// If x is ±Inf, a domain error shall occur, and a NaN shall be returned.
7477
float
7578
asinf(float x)
7679
{
7780
float t=0.0,w,p,q,c,r,s;
7881
LONG hx,ix;
82+
7983
GET_FLOAT_WORD(hx,x);
8084
ix = hx&0x7fffffff;
8185
if(ix==0x3f800000) {

library/math_asinh.c

+3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
5555
ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
5656
huge= 1.00000000000000000000e+300;
5757

58+
// If x is NaN, a NaN shall be returned.
59+
// If x is ±0, or ±Inf, x shall be returned.
5860
double
5961
asinh(double x)
6062
{
6163
double t,w;
6264
LONG hx,ix;
65+
6366
GET_HIGH_WORD(hx,x);
6467
ix = hx&0x7fffffff;
6568
if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */

library/math_asinhf.c

+3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ one = 1.0000000000e+00, /* 0x3F800000 */
5858
ln2 = 6.9314718246e-01, /* 0x3f317218 */
5959
huge= 1.0000000000e+30;
6060

61+
// If x is NaN, a NaN shall be returned.
62+
// If x is ±0, or ±Inf, x shall be returned.
6163
float
6264
asinhf(float x)
6365
{
6466
float t,w;
6567
LONG hx,ix;
68+
6669
GET_FLOAT_WORD(hx,x);
6770
ix = hx&0x7fffffff;
6871
if(ix>=0x7f800000) return x+x; /* x is inf or NaN */

0 commit comments

Comments
 (0)