Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #135003

Re: GNU Forth has a floating point floor word, but not floating point ceiling word?

From peter <peter.noreply@tin.it>
Newsgroups comp.lang.forth
Subject Re: GNU Forth has a floating point floor word, but not floating point ceiling word?
Date 2026-04-28 13:40 +0200
Organization A noiseless patient Spider
Message-ID <20260428134002.000057e7@tin.it> (permalink)
References <10se8v4$3d7tj$1@dont-email.me> <69eac411$1@news.ausics.net> <10sooig$2o6bk$1@dont-email.me>

Show all headers | View raw


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?

BR
Peter


> 
> 1 cells 4 < Abort" Tests not available for cell size < 32 bits"
> 1 cells 8 = constant 64-bit?
> 
> \ fetch double float onto the data stack for comparison
> 64-bit? [IF]
> : fetch-df ( addr -- u ) @ ;
> : equal-df = ;  \ bitwise equivalence
> [ELSE]
> : fetch-df ( addr -- ud ) 2@ ;
> : equal-df d= ; \ bitwise equivalence
> [THEN]
> 
> \ Testing bitwise inequality of positive and negative special values
> 
> create r1 8 allot   \ allot dfloat
> create r2 8 allot   \ allot dfloat
> 
> t{ F=ZERO r1 DF! -> }t
> t{ F=-ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> false }t
> 
> t{ +INF r1 DF! -> }t
> t{ -INF r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> false }t
> 
> t{ +NAN r1 DF! -> }t
> t{ -NAN r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> false }t
> 
> TESTING FLOOR with IEEE 754 Special values
> t{ F=ZERO FLOOR r1 DF! -> }t
> t{ F=ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ F=-ZERO FLOOR r1 DF! -> }t
> t{ F=-ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ -INF FLOOR r1 DF! -> }t
> t{ -INF r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ +INF FLOOR r1 DF! -> }t
> t{ +INF r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ -NAN FLOOR -NAN F= -> true }t
> t{ -NAN FLOOR +NAN F= -> true }t
> t{ +NAN FLOOR -NAN F= -> true }t
> t{ +NAN FLOOR +NAN F= -> true }t
> 
> t{  0.1e FLOOR r1 DF! -> }t
> t{ F=ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ -0.1e FLOOR r1 DF! -> }t
> t{ -1.0e r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> TESTING FCEIL with IEEE 745 values
> t{ F=ZERO FCEIL r1 DF! -> }t
> t{ F=ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ F=-ZERO FCEIL r1 DF! -> }t
> t{ F=-ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ -INF FCEIL r1 DF! -> }t
> t{ -INF r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ +INF FCEIL r1 DF! -> }t
> t{ +INF r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ -NAN FCEIL -NAN F= -> true }t
> t{ -NAN FCEIL +NAN F= -> true }t
> t{ +NAN FCEIL -NAN F= -> true }t
> t{ +NAN FCEIL +NAN F= -> true }t
> 
> t{ 0.1e FCEIL r1 DF! -> }t
> t{ 1.0e r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> t{ -0.1e FCEIL r1 DF! -> }t
> t{ F=-ZERO r2 DF! -> }t
> t{ r1 fetch-df r2 fetch-df equal-df -> true }t
> 
> \ end of tests
> \ ============
> 
> 
> 
> 

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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