Re: FP number syntax

Liste des GroupesRevenir à cl forth 
Sujet : Re: FP number syntax
De : anton (at) *nospam* mips.complang.tuwien.ac.at (Anton Ertl)
Groupes : comp.lang.forth
Date : 03. Jan 2025, 17:00:18
Autres entêtes
Organisation : Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID : <2025Jan3.170018@mips.complang.tuwien.ac.at>
References : 1 2 3 4 5
User-Agent : xrn 10.11
albert@spenarnc.xs4all.nl writes:
One step further is to use 0x for hex values, and free $ for
environment strings.

Forth systems can use 0x as hex prefix already, and in 2007 I checked
several systems <http://www.forth200x.org/number-prefixes.html>: PFE,
Gforth 0.6.9, Win32Forth (4.x and 6.x), and VFX Forth understood 0x10
as well as 0X10; iForth, bigForth, SwiftForth, and lxf did not.

Someone would need to make a proposal for making the $ prefix for hex
numbers obsolescent as a first step towards destandardization.
Meanwhile, Gforth has a recognizer for environment variables:

${HOME} type

prints "/home/anton".

Then probably one can forget BASE DECIMAL

We would need to standardize at least BASE-EXECUTE to get rid of
dealing with BASE for producing output.

1] This is not easy. I have been in many projects where floating points
were transferred in text, loosing precision.

Floating-point numbers can be losslessly converted from binary to
decimal representation and back, with losslessly meaning that you get
the same binary FP number after one cycle, and for

decimal1 -> binary1 -> decimal2 -> binary2 -> decimal3

binary1 and binary2 are the same bit pattern, and decimal2 and
decimal3 are the same string.

However, doing it for hex is admittedly much simpler.  But then, if
the issue is just to get the number from one system to the next
without having to deal with byte order and the like, you can also do
(on a system with 64-bit cells):

variable x

1.23e x df! x @ . \ prints 4608218246714312622 on Gforth

The output is an exact representation of the bit pattern.  Now on the
next system you can:

variable x 4608218246714312622 x ! x df@ f.

I tried this on iForth, SwiftForth and VFX, and it worked on all of
them, outputting "1.23", sometimes with trailing zeroes.

The conversion of "1.23e" by the Forth text interpreter and of the end
result by F. may be less precise than you would like, though.

But of course parameters
in oil drill samples need not 5 decimal places.

When writing general-purpose code, we do not know the needed accuracy,
so if it is possible to produce an "exact" result, we should do so.

The definition of "exact" is interesting in this case.  E.g., there is
no exact representation of 1.23 as binary FP number, so we generally
go for the binary FP number that is closest to the input number.
Conversely, the binary64 number with the bit pattern
4608218246714312622 can be represented exactly in decimal as
1.229999999999999982236431605997495353221893310546875, but we may
prefer to output the shortest string that, when converted back to
binary64, produces the same binary64 value (in this case "1.23").

Back to hex FP, if we go there at all, we might want to go with the
string format used in C source code: 0xhhhh.hhhp-ddd where h is a hex
digit and d is a decimal digit.

- anton
--
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: https://forth-standard.org/
   EuroForth 2024: https://euro.theforth.net

Date Sujet#  Auteur
8 Dec 24 * ANN: DX-Forth 4.5756dxf
9 Dec 24 `* Re: ANN: DX-Forth 4.5755Hans Bezemer
10 Dec 24  +* Re: ANN: DX-Forth 4.575dxf
10 Dec 24  i+- Re: ANN: DX-Forth 4.571albert
10 Dec 24  i`* Re: ANN: DX-Forth 4.573albert
10 Dec 24  i `* Re: ANN: DX-Forth 4.572dxf
11 Dec 24  i  `- Re: ANN: DX-Forth 4.571dxf
24 Dec 24  `* Re: ANN: DX-Forth 4.5749John
24 Dec 24   `* Re: ANN: DX-Forth 4.5748dxf
25 Dec 24    `* Re: ANN: DX-Forth 4.5747John
25 Dec 24     +* Re: ANN: DX-Forth 4.5745dxf
25 Dec 24     i`* FP number syntax (was: ANN: DX-Forth 4.57)44Anton Ertl
25 Dec 24     i +* Re: FP number syntax42minforth
26 Dec 24     i i`* Re: FP number syntax41dxf
26 Dec 24     i i +* Re: FP number syntax39Paul Rubin
26 Dec 24     i i i+* Re: FP number syntax36dxf
26 Dec 24     i i ii+* Re: FP number syntax30Paul Rubin
26 Dec 24     i i iii+* Re: FP number syntax2minforth
27 Dec 24     i i iiii`- Re: FP number syntax1dxf
26 Dec 24     i i iii`* Re: FP number syntax27Anton Ertl
27 Dec 24     i i iii +- Re: FP number syntax1dxf
27 Dec 24     i i iii +* Re: FP number syntax17Paul Rubin
27 Dec 24     i i iii i+* Re: FP number syntax5mhx
27 Dec 24     i i iii ii`* Re: FP number syntax4minforth
27 Dec 24     i i iii ii `* Re: FP number syntax3albert
27 Dec 24     i i iii ii  `* Re: FP number syntax2minforth
28 Dec 24     i i iii ii   `- Re: FP number syntax1albert
31 Dec 24     i i iii i`* Re: FP number syntax11Anton Ertl
1 Jan 25     i i iii i `* Re: FP number syntax10dxf
1 Jan 25     i i iii i  `* Re: FP number syntax9Bernd Linsel
1 Jan 25     i i iii i   `* Re: FP number syntax8dxf
1 Jan 25     i i iii i    +- Re: FP number syntax1dxf
1 Jan 25     i i iii i    `* Re: FP number syntax6Anton Ertl
1 Jan 25     i i iii i     +- Re: FP number syntax1HenryHH
1 Jan 25     i i iii i     `* Re: FP number syntax4dxf
1 Jan 25     i i iii i      +* Re: FP number syntax2mhx
1 Jan 25     i i iii i      i`- Re: FP number syntax1albert
1 Jan 25     i i iii i      `- Re: FP number syntax1dxf
27 Dec 24     i i iii `* Re: FP number syntax8albert
28 Dec 24     i i iii  +- Re: FP number syntax1dxf
31 Dec 24     i i iii  `* Re: FP number syntax6Anton Ertl
2 Jan 25     i i iii   `* Re: FP number syntax5Anton Ertl
3 Jan 25     i i iii    `* Re: FP number syntax4albert
3 Jan 25     i i iii     `* Re: FP number syntax3Anton Ertl
4 Jan 25     i i iii      +- Re: FP number syntax1minforth
4 Jan 25     i i iii      `- Re: FP number syntax1albert
3 Jan 25     i i ii`* Re: FP number syntax5dxf
3 Jan 25     i i ii +* Re: FP number syntax2minforth
3 Jan 25     i i ii i`- Re: FP number syntax1dxf
3 Jan 25     i i ii `* Re: FP number syntax2Anton Ertl
3 Jan 25     i i ii  `- Re: FP number syntax1minforth
26 Dec 24     i i i`* Re: FP number syntax2Anton Ertl
26 Dec 24     i i i `- Re: FP number syntax1dxf
26 Dec 24     i i `- Re: FP number syntax1mhx
25 Dec 24     i `- Re: FP number syntax (was: ANN: DX-Forth 4.57)1albert
26 Dec 24     `- Re: ANN: DX-Forth 4.571dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal