Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: minforth Newsgroups: comp.lang.forth Subject: Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Date: Tue, 28 Apr 2026 14:01:58 +0200 Lines: 83 Message-ID: References: <10se8v4$3d7tj$1@dont-email.me> <69eac411$1@news.ausics.net> <10sooig$2o6bk$1@dont-email.me> <20260428134002.000057e7@tin.it> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net 8zuGZS5uAgj8v8vabD/CvQgnfre3GEBSHP+KEwKcA1InNGSuoH Cancel-Lock: sha1:ttpc3yDaL48rYjRPX+tJstVYcnw= sha256:jiqK9jANIxFmwMlfpR42r8UjoVNGmD+JKD7qcgSIHtk= User-Agent: Mozilla Thunderbird In-Reply-To: <20260428134002.000057e7@tin.it> Xref: csiph.com comp.lang.forth:135004 Am 28.04.2026 um 13:40 schrieb peter: > On Mon, 27 Apr 2026 17:39:11 -0500 > Krishna Myneni wrote: > >> On 4/23/26 8:14 PM, dxf wrote: >>> On 24/04/2026 9:11 am, Buzz McCool wrote: >>>> $ gforth >>>> Gforth 0.7.9_20260324 >>>> ... >>>> Type `help' for basic help >>>> >>>> 1.9e floor  ok f:1 >>>> f. 1.  ok >>>> >>>> 1.9e fceil >>>> *the terminal*:6:6: error: Undefined word >>>> 1.9e >>>fceil<<< >>>> Backtrace: >>>> /usr/share/gforth/0.7.9_20260324/kernel/recognizer.fs:124:35:  0 $7DFF9A013568 throw >>> >>> : fceil ( r1 -- r2 ) fnegate floor fnegate ; ok >>> 1.9e fceil f. 2. ok >>> -1.9e fceil f. -1. ok >>> >>> >> >> You may want to check the behavior of FLOOR and FCEIL with IEEE special >> values, if your Forth system supports them. The following code should >> run on both 32-bit and 64-bit Forth systems, with or without a separate >> fp stack. Some of the tests may be redundant. >> >> -- >> KM >> >> \ ============ >> \ Requires ttester.4th >> >> DECIMAL >> 0e fconstant F=ZERO >> HEX >> >> \ Make an IEEE 754 double precision floating point value from >> \ the specified bits for the sign, binary fraction, and exponent. >> \ Return the fp value and error code with the following meaning: >> \ 0 no error >> \ 1 exponent out of range >> \ 2 fraction out of range >> fvariable temp >> >> : MAKE-IEEE-DFLOAT ( signbit udfraction uexp -- r nerror ) >> dup 800 u< invert IF 2drop 2drop F=ZERO 1 EXIT THEN >> 14 lshift 3 pick 1F lshift or >r >> dup 100000 u< invert IF >> r> 2drop 2drop F=ZERO 2 EXIT >> THEN >> r> or [ temp 4 + ] literal L! temp L! >> drop temp df@ 0 ; >> >> >> \ Constants representing -0e -INF +INF -NAN +NAN >> >> true 0 0 0 make-ieee-dfloat [IF] fdrop [ELSE] fconstant F=-ZERO [THEN] >> true 0 0 7FF make-ieee-dfloat [IF] fdrop [ELSE] fconstant -INF [THEN] >> >> [DEFINED] -INF [IF] -INF fnegate fconstant +INF [THEN] >> true 1 0 7FF make-ieee-dfloat [IF] fdrop [ELSE] fconstant -NAN [THEN] >> [DEFINED] -NAN [IF] -NAN fnegate fconstant +NAN [THEN] >> >> DECIMAL >> >> : FCEIL ( F: r1 -- r2 ) FNEGATE FLOOR FNEGATE ; >> >> \ Testing F= for positive and negative special values >> t{ +INF -INF F= -> false }t >> t{ +NAN -NAN F= -> true }t >> t{ F=ZERO F=-ZERO F= -> true }t > > How is your F= defined? > I see that it returns true for comparing two nans. > Shouldn't that return false in IEEE fp math? F= is undefined in standard Forth. However common sense should prevail indeed, or IOW the principle of least surprise.