Krishna Myneni
2024-07-10 11:16:01 UTC
Here's a simple check to see what your Forth system does when M*/ is
given arguments which will overflow a double length result. The standard
states that this is an ambiguous condition.
: ipow ( n u -- d ) 1 s>d rot 0 ?DO 2 pick 1 m*/ LOOP rot drop ;
65 21 ipow d.
117809547936177440979200839996337890625 ok \ result ok (64-bit system)
65 22 ipow d.
Floating point exception (core dumped) \ kForth-64 (since last commit)
65 raised to the power of 22 will overflow the double number result on a
64-bit system and crash on kForth-64. Prior to my recent patch it would
overflow silently and print an incorrect result.
In kForth, a SIGFPE handler may be installed as shown in the example
sigfpe.4th.
include sigfpe
\ ...
65 22 ipow d.
Floating point exception
Line 16: VM Error(-258): Return stack corrupt
65 22 ipow d.
ok \ returns to the Forth prompt
To be clear there is no floating point operation involved in IPOW as
defined above, but the exception generated for integer division overflow
for a double length number divided by a single length number generates
SIGFPE on linux.
--
Krishna
given arguments which will overflow a double length result. The standard
states that this is an ambiguous condition.
: ipow ( n u -- d ) 1 s>d rot 0 ?DO 2 pick 1 m*/ LOOP rot drop ;
65 21 ipow d.
117809547936177440979200839996337890625 ok \ result ok (64-bit system)
65 22 ipow d.
Floating point exception (core dumped) \ kForth-64 (since last commit)
65 raised to the power of 22 will overflow the double number result on a
64-bit system and crash on kForth-64. Prior to my recent patch it would
overflow silently and print an incorrect result.
In kForth, a SIGFPE handler may be installed as shown in the example
sigfpe.4th.
include sigfpe
\ ...
65 22 ipow d.
Floating point exception
Line 16: VM Error(-258): Return stack corrupt
65 22 ipow d.
ok \ returns to the Forth prompt
To be clear there is no floating point operation involved in IPOW as
defined above, but the exception generated for integer division overflow
for a double length number divided by a single length number generates
SIGFPE on linux.
--
Krishna