Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #135004
| From | minforth <minforth@gmx.net> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: GNU Forth has a floating point floor word, but not floating point ceiling word? |
| Date | 2026-04-28 14:01 +0200 |
| Message-ID | <n5blt5F2t8dU1@mid.individual.net> (permalink) |
| References | <10se8v4$3d7tj$1@dont-email.me> <69eac411$1@news.ausics.net> <10sooig$2o6bk$1@dont-email.me> <20260428134002.000057e7@tin.it> |
Am 28.04.2026 um 13:40 schrieb peter:
> On Mon, 27 Apr 2026 17:39:11 -0500
> Krishna Myneni <krishna.myneni@ccreweb.org> 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.
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar
GNU Forth has a floating point floor word, but not floating point ceiling word? Buzz McCool <buzz_mccool@yahoo.com> - 2026-04-23 16:11 -0700
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? dxf <dxforth@gmail.com> - 2026-04-24 11:14 +1000
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Buzz McCool <buzz_mccool@yahoo.com> - 2026-04-24 08:29 -0700
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-27 17:39 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? peter <peter.noreply@tin.it> - 2026-04-28 13:40 +0200
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? minforth <minforth@gmx.net> - 2026-04-28 14:01 +0200
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-28 19:25 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? dxf <dxforth@gmail.com> - 2026-04-29 11:20 +1000
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-29 08:30 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-29 20:15 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-02 15:56 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? dxf <dxforth@gmail.com> - 2026-04-29 11:47 +1000
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-30 04:40 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-30 05:37 -0500
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? peter <peter.noreply@tin.it> - 2026-04-30 15:55 +0200
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-30 20:49 -0500
Special memory access words (was: GNU Forth has a ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-01 06:16 +0000
Re: Special memory access words (was: GNU Forth has a ...) peter <peter.noreply@tin.it> - 2026-05-01 10:22 +0200
Re: Special memory access words (was: GNU Forth has a ...) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-01 08:57 +0000
Re: Special memory access words Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-01 10:19 -0500
Re: Special memory access words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-01 15:35 +0000
Re: Special memory access words Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-01 13:28 -0500
Re: Special memory access words Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-01 13:30 -0500
Re: Special memory access words anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-05-02 05:54 +0000
Re: Special memory access words Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-05-02 15:49 -0500
Re: Special memory access words Hans Bezemer <the.beez.speaks@gmail.com> - 2026-05-01 13:28 +0200
Re: GNU Forth has a floating point floor word, but not floating point ceiling word? peter <peter.noreply@tin.it> - 2026-05-01 10:18 +0200
csiph-web