Commit graph

11 commits

Author SHA1 Message Date
Jeronimo Pellegrini
ce97808201 Add missing constants to SRFI-144
The following constants were missing from Chibi's SRFI-144
implementation:

 fl-1/e
 fl-e-pi/4
 fl-1/log-2
 fl-log-3
 fl-log-pi
 fl-1/log-10
 fl-2pi
 fl-pi-squared
 fl-degree
 fl-gamma-1/2
 fl-gamma-1/3
 fl-gamma-2/3
2021-09-29 00:57:31 -03:00
Alexei Lozovsky
6f35aa75f4
Fix usage of signbit() in SRFI 144
C standard defines signbit() as a macro returning "non-zero value" for
negative arguments (see 7.12.3.6 of C11 standard). SRFI 144's flsign-bit
is defined to return exactly 1.

Make sure to convert the result of signbit() call into "boolean int"
which is either 0 or 1.

This is not a theoretical issue. This causes SRFI 144 test suite to fail
on many architectures that are not x86_64.

GCC on x86_64 compiles signbit() as

        movmskpd %xmm0, %eax
        andl     $1, %eax

which indeed returns either 0 or 1. movmskpd extracts 2-bit sign mask
from the FP value in src register and stores that in low-order bits of
the dst register. Then the unneded extra bit is masked out, leaving only
the lowest bit set or unset.

However, other architectures don't have such conveniences and go with
more direct approach. For example, GCC on ARMv7 produces this:

        sub     sp, sp, #8
        vstr.64 d0, [sp]
        ldr     r0, [sp, #4]
        and     r0, r0, #0x80000000
        add     sp, sp, #8
        bx      lr

which effectively returns either 0 or -1. Generated code masks out
everything but the sign bit and returns the result as is. The value
0x80000000 is the representation of -1.

Even on i386 signbit() is compiled as

        fldl    4(%esp)
        fxam
        fnstsw  %ax
        fstp    %st(0)
        andl    $512, %eax
        ret

which effectively returns either 0 or 512: fxam sets C1 bit FPU status
word to the sign of FP value, then the status word is extracted, the
"sign bit" is masked out, and left as is.
2021-06-06 13:49:44 +09:00
Arvydas Silanskas
cf40f1aca1 add fl-epsilon to srfi 144 2020-08-11 21:26:42 +03:00
Alex Shinn
dc524feabc add missing trailing ? on SRFI 144 inequality ops 2020-08-11 10:37:23 +09:00
okuoku
51f24ed36e Win32: Import Ruby's lgamma_r implementation (Public Domain)
Import Ruby's lgamma_r implementation as MSVCRT missing lgamma_r
implementation. Non Windows platforms should continue to use lgamma_r
implementation which provided with its C runtime library.
2017-12-13 17:20:53 +09:00
okuoku
735719d9d6 Win32: Port/Stub-out libraries
- (scheme time): Win32 stub impl
 - (chibi filesystem): Win32 stubbing
 - (chibi process): ditto
 - (chibi time): ditto
 - SRFI-144: lgamma is not in C99 standard
 - SRFI-27: Win32 INSECURE rand
2017-11-06 04:10:28 +09:00
Alex Shinn
836ddf6397 adding missing flonum to (srfi 144) (fixes issue #434) 2017-08-09 22:46:46 +09:00
Marc Nieper-Wißkirchen
0078ae2e83 Repair emscripten build 2017-07-25 16:06:59 +02:00
Alex Shinn
d93f7265e2 fixing test after jn/yn signature change 2017-07-20 22:18:05 +09:00
Alex Shinn
071aa725fd updating (srfi 144) with final changes (issue #426) 2017-07-20 22:12:01 +09:00
Alex Shinn
b52711cac8 adding (srfi 144) 2017-06-03 16:49:09 +09:00