Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions src/libc/acoshl.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <math.h>
#include "__float64_constants.h"

/* enable when log1pl is implemented */
#if 0

/**
* @remarks Minimum relative precision of:
* 2^-42.37 at +1.000000358e+00 with ideal log1pl
Expand All @@ -15,14 +12,3 @@ long double acoshl(long double x) {
}
return logl(x) + F64_LN2;
}

#else

long double acoshl(long double x) {
if (x < 0x1.0p+511L) {
return logl(x + sqrtl(x * x - 1.0L));
}
return logl(x) + F64_LN2;
}

#endif
18 changes: 4 additions & 14 deletions src/libc/atanhl.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
#include <math.h>

/* enable when log1pl is implemented */
#if 0

/**
* @remarks Relative precision of:
* 2^-51 at +1.277396381e-01 with ideal log1pl
* @remarks Minimum ulp:
* ulp of -2 at +0x1.cf33c905a6324p-4 with ideal log1pl
* ulp of +4098 at +0x1.ffff1c95280b8p-15 with current log1pl and ideal logl
* ulp of +4135 at -0x1.f319bfec310c4p-14 with current log1pl and logl
*/
long double atanhl(long double arg) {
long double x = fabsl(arg);
x = 0.5L * log1pl((2.0L * x) / (1.0L - x));
return copysignl(x, arg);
}

#else

long double atanhl(long double x)
{
return 0.5L * logl((1.0L + x) / (1.0L - x));
}

#endif
1 change: 0 additions & 1 deletion src/libc/ceilf.src
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ _ceilf:
ld e,a
push bc
pop hl
ld sp,ix
pop ix
ret

Expand Down
14 changes: 14 additions & 0 deletions src/libc/expm1l.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <math.h>
#include "__float64_constants.h"

/**
* @remarks Approximate minimum ulp:
* ulp of -4098 at +0x1.3683c27b9c856p-13 with ideal expl
*/
long double expm1l(long double x) {
if (fabsl(x) < 0x1.0p-13L) {
long double x_sqr = x * x;
return (x_sqr * x) * F64_1_DIV_3 + 0.5L * (x_sqr) + x;
}
return expl(x) - 1.0L;
}
14 changes: 14 additions & 0 deletions src/libc/log1pl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <math.h>
#include "__float64_constants.h"

/**
* @remarks Approximate minimum ulp:
* ulp of +4097 at +0x1.0003239899b0ap-13 with ideal expl
*/
long double log1pl(long double x) {
if (fabsl(x) < 0x1.2p-13L) {
long double x_sqr = x * x;
return (x_sqr * x) * F64_1_DIV_3 - 0.5L * (x_sqr) + x;
}
return logl(1.0L + x);
}
14 changes: 0 additions & 14 deletions src/libc/modff.c

This file was deleted.

89 changes: 85 additions & 4 deletions src/libc/modff.src
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,91 @@ _modf := _modff

else

_modff := __modff_c
_modf := __modf_c
; float modf(float x, float* iptr)
_modff:
_modf:
call __frameset0

extern __modff_c
extern __modf_c
; copy the mantissa into HL and BC
sbc hl, hl
ld bc, (ix + 6) ; mantissa
add hl, bc
adc hl, hl
ld a, (ix + 9) ; exponent
ld e, a
rla
ld d, a
jr z, .maybe_inf
inc a
ld a, e
jr z, .ret_nan
.not_inf:
ld a, d
sub a, 127 ; |x| < 1.0f
jr c, .less_than_one
; fintie and normal
ld hl, (ix + 6) ; mantissa
; E has exponent
push de
push hl
call _truncf
pop af, af

ld a, e
ex hl, de
ld hl, (ix + 12) ; float *iptr
ld (hl), de
inc hl
inc hl
inc hl
ld (hl), a
ex hl, de
ld e, a
ld bc, (ix + 6)
ld a, (ix + 9)

call __fsub
push bc
pop hl
ld e, a
pop ix
ret

.maybe_inf:
inc a
jr nz, .not_inf
ld a, e
ld hl, (ix + 12) ; float *iptr
ld (hl), bc
inc hl
inc hl
inc hl
ld (hl), a ; inf exp
xor a, a
ld e, a
sbc hl, hl
pop ix
ret

.less_than_one:
ld bc, 0
ld a, e
and a, $80
; A:UBC = copysignf(0.0f, x)
.ret_nan:
ld hl, (ix + 12) ; float *iptr
ld (hl), bc
inc hl
inc hl
inc hl
ld (hl), a
ld hl, (ix + 6) ; mantissa
; E has exponent
pop ix
ret

extern __frameset0
extern _truncf
extern __fsub

end if
19 changes: 0 additions & 19 deletions src/libc/truncf.c

This file was deleted.

46 changes: 46 additions & 0 deletions src/libc/truncf.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
assume adl=1

section .text

public _truncf, _trunc

_trunc:
_truncf:
ld iy, 0
add iy, sp
ld e, (iy + 6)
ld bc, (iy + 3)
sbc hl, hl
add hl, bc ; copy BC to HL
add hl, hl
ld a, e
rla

sub a, 127 ; exponent bias
jr c, .ret_zero
sub a, 23 ; bits in the mantissa
jr nc, .ret_self
sbc hl, hl ; HL = 0xFFFFFF
neg
ld d, c ; store C
ld c, a
call __ishl
ld c, d ; restore C
jp __iand

.ret_self:
; already (large) integer, inf, or NaN
sbc hl, hl
add hl, bc
ret

.ret_zero:
; return signed zero
ld a, e
and a, $80
ld e, a
sbc hl, hl
ret

extern __ishl
extern __iand
43 changes: 43 additions & 0 deletions test/floating_point/float32_modf/autotest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"transfer_files": [
"bin/DEMO.8xp"
],
"target": {
"name": "DEMO",
"isASM": true
},
"sequence": [
"action|launch",
"delay|1000",
"hashWait|1",
"key|enter",
"delay|300",
"hashWait|2"
],
"hashes": {
"1": {
"description": "All tests passed or GDB1 error",
"timeout": 5000,
"start": "vram_start",
"size": "vram_16_size",
"expected_CRCs": [
"38E2AD5A",
"2C812DC2"
]
},
"2": {
"description": "Exit or GDB1 error",
"start": "vram_start",
"size": "vram_16_size",
"expected_CRCs": [
"FFAF89BA",
"101734A5",
"9DA19F44",
"A32840C8",
"349F4775",
"271A9FBF",
"82FD0B1E"
]
}
}
}
17 changes: 17 additions & 0 deletions test/floating_point/float32_modf/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ----------------------------
# Makefile Options
# ----------------------------

NAME = DEMO
ICON = icon.png
DESCRIPTION = "CE C Toolchain Demo"
COMPRESSED = NO

CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c11
CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11

PREFER_OS_LIBC = NO

# ----------------------------

include $(shell cedev-config --makefile)
Loading
Loading