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


Groups > comp.lang.forth > #135266

Re: kForth-Win32 fix for decimal string to double float conversion

From Krishna Myneni <krishna.myneni@ccreweb.org>
Newsgroups comp.lang.forth
Subject Re: kForth-Win32 fix for decimal string to double float conversion
Date 2026-07-25 13:17 -0500
Organization A noiseless patient Spider
Message-ID <1142uj0$1m890$1@dont-email.me> (permalink)
References <113lcfk$18opt$1@dont-email.me> <nnd$10021294$12a53193@9ed426c01832dcf1> <113nkmm$1u1in$1@dont-email.me> <nnd$245e5ae0$2ade0865@74903abd065dd450>

Show all headers | View raw


On 7/25/26 09:08, albert@SPENARNC.XS4ALL.NL wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
>> On 7/21/26 04:40, albert@SPENARNC.XS4ALL.NL wrote:
>>> Krishna Myneni <krishna.myneni@ccreweb.org> wrote:
>> ...
>>>>
>>>> Using double number arithmetic on a 64-bit Forth system, you may easily
>>>> verify that the correct round to nearest representable floating point
>>>> value is the one represented by the binary pattern 3ff00000 00000001 ,
>>>> rather than to the exactly representable value of 1.000.... (pattern
>>>> 3ff00000 00000000):
>>>
>>> If a number contains an exponent character, denoting a floating point,
>>> I convert this floating point number from the end. This had nothing
>>> to do with 32/64 bit system as it runs in the floating point 8087.
>>> In this case I remember the exponent first.
>>> start with 0,
>>> add 1 , divide by 10
>>> add 5 , 5 divide by 10
>>> ..
>>> decimal point, remember the place.
>>>
>>> The initial floating point number is 1/10 , the rounding mode
>>> doesn't matter much, because a host of larger numbers have been added.
>>>
>>>    1.000000000000000111022302462515654042363166809082031251E0 FS.
>>>    1.000000000000000110E0
>>>
>> ...
>>
>> I think you misunderstood the referenced paragraph. It has to do with
>> checking the conversion to see which of the adjacent representable
>> double precision numbers is the nearest one when the rounding mode is
>> set to nearest. It is possible to do this with integer arithmetic but
>> one needs double length 64-bit cell numbers to do it for the examples
>> given above.
> 
> If you set rounding mode to nearest, you expect to get the
> nearest result ???

The nearest result to within 1 ulp which can be represented with 53 bit 
significand.

Not all C libraries provide a string to double float conversion which 
actually rounds to the nearest representable IEEE double precision float 
for all cases. 32-bit GCC's libraries also failed to convert to the 
nearest prior to sometime in the early 2000s. It is true for the last 
version of the libc supplied with the Digital Mars C/C++ (formerly 
Symantec C/C++) compiler for 32-bit Windows.

Forth systems based on those C libraries, using the built-in strtod() or 
atof() functions for converting strings to double precision floats will 
fail on some test cases. This is what the tests in fpio-test.4th aim to 
catch.




> 
> Default is round to nearest.
> If you start at the end with the conversion all the intermediate results
> are round to nearest.
> You process 60 digits and shift 40 digits into oblivion.
> The last digit is 1. If this is the 60th decimal it is divided by 10 sixty
> times. There is nothing left of the poor 1, let alone of its rounding
> errors.
> 
> I think there is no need to check the end result with my method,
> unless I'm thoroughly mistaken.
> 

Run the fpio-tests for your input conversions to check. In your prior 
message, you showed me an output which is not even representable in 
double precision.

> Groetjes Albert
> 
> P.S.
> I do not buy that 10e100 FSIN becomes any better if you do the
> range reduction with utmost precision.
> 

If you don't believe it, try providing such large arguments to the FSIN 
FCOS or FTAN instructions of the x87 FPU and see for yourself.

--
Krishna

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


Thread

kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-20 09:48 -0500
  Re: kForth-Win32 fix for decimal string to double float conversion albert@SPENARNC.XS4ALL.NL - 2026-07-21 11:40 +0200
    Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-21 06:20 -0500
      Re: kForth-Win32 fix for decimal string to double float conversion albert@SPENARNC.XS4ALL.NL - 2026-07-25 16:08 +0200
        Re: kForth-Win32 fix for decimal string to double float conversion peter <peter.noreply@tin.it> - 2026-07-25 17:07 +0200
          Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-25 13:22 -0500
            Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-25 13:30 -0500
        Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-25 13:17 -0500
          Re: kForth-Win32 fix for decimal string to double float conversion dxf <dxforth@gmail.com> - 2026-07-26 13:15 +1000
            Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-26 07:18 -0500
              Re: kForth-Win32 fix for decimal string to double float conversion dxf <dxforth@gmail.com> - 2026-07-31 14:54 +1000
                Re: kForth-Win32 fix for decimal string to double float conversion anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-07-31 08:35 +0000
                Re: kForth-Win32 fix for decimal string to double float conversion albert@spenarnc.xs4all.nl - 2026-07-31 12:05 +0200
                Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-31 07:54 -0500
                Re: kForth-Win32 fix for decimal string to double float conversion anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-07-31 16:55 +0000
                Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-31 14:40 -0500
                Re: kForth-Win32 fix for decimal string to double float conversion anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-08-01 08:23 +0000
                Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-01 06:42 -0500
    Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-21 11:30 -0500
      Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-21 14:47 -0500
  Re: kForth-Win32 fix for decimal string to double float conversion albert@SPENARNC.XS4ALL.NL - 2026-07-25 23:42 +0200
    Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-25 18:47 -0500
      Re: kForth-Win32 fix for decimal string to double float conversion albert@SPENARNC.XS4ALL.NL - 2026-07-26 13:11 +0200
  Re: kForth-Win32 fix for decimal string to double float conversion albert@SPENARNC.XS4ALL.NL - 2026-07-26 13:22 +0200
    Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-26 07:23 -0500
      Re: kForth-Win32 fix for decimal string to double float conversion albert@SPENARNC.XS4ALL.NL - 2026-07-26 20:13 +0200
        Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-07-27 12:20 -0500
  Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-11 07:24 -0500
  Re: kForth-Win32 fix for decimal string to double float conversion Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-24 18:55 -0500

csiph-web