Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #135687
| Date | 2026-09-13 03:14 +1000 |
|---|---|
| Subject | Re: ddfloat library: the behavior of >dd |
| Newsgroups | comp.lang.forth |
| References | (2 earlier) <1180jpe$16qki$1@dont-email.me> <1181v83$17dme$1@dont-email.me> <11829tr$3chqi$1@dont-email.me> <11833g2$1818h$1@dont-email.me> <6aa549e4$1@news.ausics.net> |
| From | dxf <dxforth@gmail.com> |
| Message-ID | <6aa58871$1@news.ausics.net> (permalink) |
| Organization | Ausics - https://newsgroups.ausics.net |
In addition to NAN/INFs causing DDFS. to enter an infinite loop, numbers that
are too small/large can also do so. Below is a patch that attempts to fix
these issues. The patch can be applied to the DDFLOAT version here:
https://pastebin.com/TdcLJhXP
Implementation of the NAN? function I leave to users as there several options -
none of which are easy, portable, and foolproof. But I'm always willing to be
surprised.
---8<---
\ Patch for DDFLOAT.F 2026-09-13
\
\ Fix infinite loop displaying floats that are:
\ - too small/large
\ - NAN/INF **
\
\ ** requires a function that can detect NAN/INF e.g.
\ NAN? ( F: r -- ) ( -- flag )
\
: fzero ( x xx -- ) DDDROP S" 0.E0" HOLDS 0 ;
: range? ( r -- r 0 | -1 ) \ handle problem numbers
FOVER F0= IF fzero EXIT THEN
\ FDUP NAN? >R FOVER NAN? R> OR IF
\ DDDROP S" NAN/INF" HOLDS 0 EXIT
\ THEN
getpower dup -298 < IF drop fzero EXIT THEN
299 > IF DDDROP S" INF" HOLDS 0 EXIT THEN
-1
;
: (DDFS.) ( dd -- c-addr u ) \ string double-double in E-format
<# range? IF
getsign >R
getpower ( x xx n)
normalize >R ( y yy)
peeldigits copydigits
dig$ maxdig ( a u) 0digit-fix R> + \ adjust exp
( p) DUP ABS 0 #S 2DROP SIGN \ exponent
[char] E HOLD ( a u)
1- OVER 1+ SWAP HOLDS [char] . HOLD C@ HOLD
R> ( s) IF [char] - HOLD THEN
THEN 0 0 #>
;
\\
cr
ok
dd# 1e-296 ddfs. 1.0000000000000000000000000000000E-296 ok
dd# 1e-297 ddfs. 1.0000000000000000000000000000000E-297 ok
dd# 1e-298 ddfs. 1.0000000000000000000000000000000E-298 ok
dd# 1e-299 ddfs. 0.E0 ok
dd# 1e-300 ddfs. 0.E0 ok
dd# 1e-301 ddfs. 0.E0 ok
dd# 1e-302 ddfs. 0.E0 ok
dd# 1e-303 ddfs. 0.E0 ok
cr
ok
dd# 1e+296 ddfs. 1.0000000000000000000000000000001E296 ok
dd# 1e+297 ddfs. 1.0000000000000000000000000000001E297 ok
dd# 1e+298 ddfs. 1.0000000000000000000000000000001E298 ok
dd# 1e+299 ddfs. 1.0000000000000000000000000000001E299 ok
dd# 1e+300 ddfs. INF ok
dd# 1e+301 ddfs. INF ok
\ dd# 1e+302 ddfs. NAN/INF ok
\ dd# 1e+303 ddfs. NAN/INF ok
\ dd# 1e+304 ddfs. NAN/INF ok
\ dd# 1e+305 ddfs. NAN/INF ok
---8<---
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-10 19:33 +0200
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-10 13:35 -0500
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-10 22:10 +0200
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-10 16:51 -0500
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-11 12:16 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-11 12:05 +0200
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-12 00:27 +0200
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-11 20:29 -0500
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-12 12:02 +1000
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-12 10:24 -0500
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-12 10:45 +0200
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-12 19:51 +1000
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-12 22:47 +1000
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-13 03:14 +1000
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-12 13:02 -0500
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-13 15:44 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-13 09:00 +0200
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-13 20:33 +1000
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-14 13:28 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-14 10:09 +0200
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-14 20:00 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-14 12:22 +0200
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-14 21:59 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-14 14:26 +0200
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-15 01:32 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-14 21:08 +0200
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-14 15:25 -0500
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-15 13:11 +1000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-15 14:06 +0200
Re: ddfloat library: the behavior of >dd dxf <dxforth@gmail.com> - 2026-09-16 00:05 +1000
Re: ddfloat library: the behavior of >dd anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-09-14 15:00 +0000
Re: ddfloat library: the behavior of >dd marcel hendrix <mhx@iae.nl> - 2026-09-14 21:15 +0200
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-14 15:29 -0500
Re: ddfloat library: the behavior of >dd anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-09-14 20:58 +0000
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-15 07:33 -0500
Re: ddfloat library: the behavior of >dd anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-09-15 15:53 +0000
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-15 15:23 -0500
Re: ddfloat library: the behavior of >dd Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-15 17:53 -0500
csiph-web