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


Groups > comp.lang.forth > #135025

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-30 15:55 +0200
Organization A noiseless patient Spider
Message-ID <20260430155547.000018f1@tin.it> (permalink)
References <10se8v4$3d7tj$1@dont-email.me> <69eac411$1@news.ausics.net> <10sooig$2o6bk$1@dont-email.me> <10sv81o$ii2l$1@dont-email.me> <10svbcp$ii2l$2@dont-email.me>

Show all headers | View raw


On Thu, 30 Apr 2026 05:37:13 -0500
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

> On 4/30/26 4:40 AM, Krishna Myneni wrote:
> > On 4/27/26 5:39 PM, Krishna Myneni wrote:
> > ...
> 
> Just realized that the following tests are doing nothing more than 
> testing F= rather than testing FLOOR and FCEIL. In order to test that 
> FLOOR and FCEIL are returning a valid NAN, one should check the bit 
> pattern against any valid representation of a NAN.
> 
> > t{ -NAN FLOOR -NAN F= -> false }t
> > t{ -NAN FLOOR +NAN F= -> false }t
> > t{ +NAN FLOOR -NAN F= -> false }t
> > t{ +NAN FLOOR +NAN F= -> false }t
> > 
> 
> > t{ -NAN FCEIL -NAN F= -> false }t
> > t{ -NAN FCEIL +NAN F= -> false }t
> > t{ +NAN FCEIL -NAN F= -> false }t
> > t{ +NAN FCEIL +NAN F= -> false }t
> > 
> Meaningful tests for FLOOR and FCEIL may be done with the word FNAN? 
> which checks for any valid representation of NAN. Thus the tests above 
> should be replaced by
> 
> t{ -NAN FLOOR FNAN? -> true }t
> t{ +NAN FLOOR FNAN? -> true }t
> 
> t{ -NAN FCEIL FNAN? -> true }t
> t{ +NAN FLOOR FNAN? -> true }t
> 
> The word FNAN? is defined below. Your system must provide the following 
> words:
> 
> L!  ( n addr -- )  \ perform a 32-bit store to addr
> UL@ ( addr -- u )  \ perform an unsigned 32-bit fetch from addr
> 
> For 32-bit systems L! and UL@ are simply ! and @ .
> 64-bit systems will need to provide these words intrinsically.
> 
> The revised test code is given below.

Now the test cases run without error on both lxf and lxf64

In lxf64 ABORT" is a compile only word so I just commented out that

I have L@ for zero extended fetch and <L@ for sign extended.
That works well also for C@ and <C@ ( and W@, <W@)

I had already FNAN? defined as : FNAN? FDUP F<> ;

Thanks for your test program I found that I had misspelled FCEIL
It was named FCIEL, probably after the Italian word cielo (sky)
( I live since more that 30 years in Italy)

More importantly I found that f< and friends behaved differently
when they were followed by an IF, not always treating nans correctly

BR
Peter

> 
> --
> KM
> 
> \ ============
> \ Requires ttester.4th
> 
> DECIMAL
> 
> 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]
> 
> 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 ;
> 
> : FSIGNBIT ( F: r -- ) ( -- minus? )
>      temp df! [ temp 4 + ] literal UL@ 80000000 and 0<> ;
> 
> : FEXPONENT ( F: r -- ) ( -- u )
>      temp df! [ temp 4 + ] literal UL@ 14 rshift 7FF and ;
> 
> : FFRACTION ( F: r -- ) ( -- ud )
>      temp df! temp UL@  [ temp 4 + ] literal UL@ 000FFFFF and ;
> 
> : FINITE?  ( F: r -- ) ( -- [normal|subnormal]? ) fexponent 7FF <> ;
> 
> : FNORMAL? ( F: r -- ) ( -- normal? )  fexponent 0<> ;
> 
> : FSUBNORMAL? ( F: r -- ) ( -- subnormal? )  fexponent 0= ;
> 
> : FINFINITE? ( F: r -- ) ( -- [+/-]Inf? )
>     finite? invert ;
> 
> : FNAN? ( F: r -- ) ( -- nan? )
>     fdup FEXPONENT 7FF = >r FFRACTION D0= invert r> and ;
> 
> \ 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{ F=ZERO F=-ZERO F= -> true }t
> t{ +NAN -NAN F= -> false }t
> 
> \ Verify FNAN? recognizes both +NAN and -NAN as a NAN
> t{ +NAN FNAN? -> true }t
> t{ -NAN FNAN? -> true }t
> 
> \ 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 FNAN? -> true }t
> t{ +NAN FLOOR FNAN? -> 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 FNAN? -> true }t
> t{ +NAN FCEIL FNAN? -> 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