Discussion:
Display Engineering Notation with SI Prefix
Add Reply
dxf
2024-08-28 15:32:44 UTC
Reply
Permalink
\ Display Engineering Notation with SI Prefix
\
\ Note: If DX-Forth, VFX Forth or Win32Forth with
\ replacement f/p package is available then the code
\ block defining (FE.) may be disabled.
\
\ Inspired by iForth's (F.N) functions
\
\ This code is Public Domain

https://pastebin.com/jd676RC7
dxf
2024-08-29 10:02:26 UTC
Reply
Permalink
Post by dxf
\ Display Engineering Notation with SI Prefix
\
\ Note: If DX-Forth, VFX Forth or Win32Forth with
\ replacement f/p package is available then the code
\ block defining (FE.) may be disabled.
\
\ Inspired by iForth's (F.N) functions
\
\ This code is Public Domain
https://pastebin.com/jd676RC7
The (FE.) simulation didn't work for PREC < 3 . Here's a fix:

: (FE.) ( r n -- adr len ) \ *** only handles n = -1 ***
drop fb 3 [char] 0 fill fb precision represent <# if
Post by dxf
r 1- s>d 3 fm/mod 3 * dup abs 0 #s rot sign
[char] E hold rot fb precision 3 max rot 1+ /str
[char] 0 trim tuck holds if [char] . hold then
holds r> sign
else fb precision -trailing holds then #> ;

The following now works ...

1.234e 1e2 f* 2 1 (eng.) type 120 ok

The real (FE.) has no such issues and works as expected ...

VFX Forth 64 for Windows x64
© MicroProcessor Engineering Ltd, 1998-2023

Version: 5.43 [build 4241]
Build date: 22 December 2023

2 set-precision ok
1.234e 1e2 f* -1 (fe.) type 120.E0 ok
mhx
2024-08-29 10:39:34 UTC
Reply
Permalink
[..]
Post by dxf
The real (FE.) has no such issues and works as expected ...
VFX Forth 64 for Windows x64
© MicroProcessor Engineering Ltd, 1998-2023
Version: 5.43 [build 4241]
Build date: 22 December 2023
2 set-precision ok
1.234e 1e2 f* -1 (fe.) type 120.E0 ok
Using the non-standard set-precision of iForth:

FORTH> 2 set-precision 1.234e f. 1.23 ok
FORTH> 1 set-precision 1.234e f. 1.2 ok
FORTH> 3 set-precision 1.234e f. 1.234 ok
FORTH> 3 set-precision 1234e f. 1234.000 ok
FORTH> 0 set-precision 1234e f. 1234 ok

Didn't F83 have DIGITS ?

-marcel
dxf
2024-08-29 12:39:20 UTC
Reply
Permalink
[..]
Post by dxf
The real (FE.) has no such issues and works as expected ...
VFX Forth 64 for Windows x64
  © MicroProcessor Engineering Ltd, 1998-2023
 Version: 5.43 [build 4241]
 Build date: 22 December 2023
2 set-precision  ok
1.234e 1e2 f* -1 (fe.) type 120.E0 ok
FORTH> 2 set-precision 1.234e f. 1.23  ok
FORTH> 1 set-precision 1.234e f. 1.2  ok
FORTH> 3 set-precision 1.234e f. 1.234  ok
FORTH> 3 set-precision 1234e  f. 1234.000  ok
FORTH> 0 set-precision 1234e  f. 1234  ok
So iForth PRECISION equates to 'decimal places'. In VFX 'decimal
places' is achieved thus:

1.234e 2 0 f.r 1.23 ok
1.234e 1 0 f.r 1.2 ok
1.234e 3 0 f.r 1.234 ok
1234e 3 0 f.r 1234.000 ok
1234e 0 0 f.r 1234. ok

PRECISION only comes into effect in 'significant digits' mode:

3 set-precision

1.234e -1 0 f.r 1.23 ok
12.34e -1 0 f.r 12.3 ok
123.4e -1 0 f.r 123. ok
1234.e -1 0 f.r 1230. ok

or simply:

1.234e f. 1.23 ok
12.34e f. 12.3 ok
123.4e f. 123. ok
1234.e f. 1230. ok
Didn't F83 have DIGITS ?
Neither Laxen/Perry F83 nor Forth-83 had floating point. You may be
thinking of PLACES from 'The Forth Vendors Group Standard Floating
Point Extension' (?) That was initially considered by the ANS-TC and
documented in BASIS17:

12.1.2032 PLACES

( u -- )

Set the number of decimal places (digits to the right of the radix
point) displayed by E. and F.

PLACES would be synonymous with your PRECISION .

Has any language other that Forth opted for 'significant digits' over
(or in addition to) 'decimal places'? The former seems particularly
suited to engineering.
mhx
2024-08-29 14:23:33 UTC
Reply
Permalink
On Thu, 29 Aug 2024 12:39:20 +0000, dxf wrote:

[..]
Post by dxf
So iForth PRECISION equates to 'decimal places'.
Yes. I appreciate the mathematical rigor of SET-PRECISION,
but literally *none* of my academic and engineering friends
*ever* complained about iForth's evil deviation. Who really
likes to see

-1e 0e 0.5e 0e z^ z. 0.0000000000000000612323399573677 + i1. ok

3 set-precision ok
-1e 0e 0.5e 0e z^ z. 0.0000000000000000612 + i1. ok

in computed output?
Post by dxf
Post by mhx
Didn't F83 have DIGITS ?
Neither Laxen/Perry F83 nor Forth-83 had floating point. You may be
thinking of PLACES from 'The Forth Vendors Group Standard Floating
Point Extension' (?)
Yes, that was it. Although one actually wants PLACES, I can
understand why it makes more sense to standardize SET-PRECISION .
Post by dxf
Has any language other that Forth opted for 'significant digits' over
(or in addition to) 'decimal places'? The former seems particularly
suited to engineering.
Not that I know of ...

The problem with PLACES is that a printout of results after a
few hours of number-crunching may be useless when
one has estimated the range of the likely outcomes wrong.

-marcel
dxf
2024-08-30 02:13:43 UTC
Reply
Permalink
Post by mhx
[..]
Post by dxf
So iForth PRECISION equates to 'decimal places'.
Yes. I appreciate the mathematical rigor of SET-PRECISION,
but literally *none* of my academic and engineering friends
*ever* complained about iForth's evil deviation. Who really
likes to see
-1e 0e 0.5e 0e z^ z.  0.0000000000000000612323399573677 + i1.  ok
3 set-precision  ok
-1e 0e 0.5e 0e z^ z.  0.0000000000000000612 + i1.  ok
in computed output?
Can't say without knowing what was the criteria. If a user wants
to show the result to 3 significant digits, who can argue with that.
3 significant digits is about right for (ENG.) applications.
mhx
2024-08-30 06:30:20 UTC
Reply
Permalink
On Fri, 30 Aug 2024 2:13:43 +0000, dxf wrote:
[..]
Post by dxf
Post by mhx
3 set-precision  ok
-1e 0e 0.5e 0e z^ z.  0.0000000000000000612 + i1.  ok
[..]
Post by dxf
Can't say without knowing what was the criteria. If a user wants
to show the result to 3 significant digits, who can argue with that.
3 significant digits is about right for (ENG.) applications.
When the user wants 3 significant digits according to the mathematical
definition there is no discussion that SET-PRECISION is appropriate.

If a system is to produce 100 Watts, and an approximate model of the
losses returns 0.0000000000000000612 Watts, then that is quite probably
not the wanted output (because it tells you the resolution of the
floating point package, not the accuracy of the approximation).
However, when that same model returns 100 Watts for the full output
power, 100 or 100.0 is (probably) the expectation. Extra steps are
needed
to print the losses in a useful way, and those steps match perfectly
with PLACES. PLACES would also work to print the full power as 100.
It is not ideal, but the reason it is not ideal has nothing to do with
SET-PRECISION .

-marcel
dxf
2024-08-30 08:03:26 UTC
Reply
Permalink
Post by mhx
[..]
Post by mhx
3 set-precision  ok
-1e 0e 0.5e 0e z^ z.  0.0000000000000000612 + i1.  ok
[..]
Can't say without knowing what was the criteria.  If a user wants
to show the result to 3 significant digits, who can argue with that.
3 significant digits is about right for (ENG.) applications.
When the user wants 3 significant digits according to the mathematical
definition there is no discussion that SET-PRECISION is appropriate.
If a system is to produce 100 Watts, and an approximate model of the
losses returns 0.0000000000000000612 Watts, then that is quite probably
not the wanted output (because it tells you the resolution of the
floating point package, not the accuracy of the approximation).
However, when that same model returns 100 Watts for the full output
power, 100 or 100.0 is (probably) the expectation. Extra steps are
needed
to print the losses in a useful way, and those steps match perfectly
with PLACES. PLACES would also work to print the full power as 100.
It is not ideal, but the reason it is not ideal has nothing to do with
SET-PRECISION .
If the argument is certain apps work well with PLACES (or equivalent)
I can accept that. Because Fortran and C had it from the beginning
I felt it was important to provide it. At the same time I also found
SET-PRECISION to be useful. I can't imagine FE. being used with
anything but SET-PRECISION. So for me, an fp package needs to offer
both schemes.
mhx
2024-08-30 08:26:26 UTC
Reply
Permalink
Post by dxf
At the same time I also found
SET-PRECISION to be useful.
An example would be instructive.

-marcel
dxf
2024-08-30 09:24:18 UTC
Reply
Permalink
Post by mhx
Post by dxf
At the same time I also found
SET-PRECISION to be useful.
An example would be instructive.
Standard capacitor and resistor values are specified in terms
of significant digits.
dxf
2024-08-31 01:11:59 UTC
Reply
Permalink
Post by dxf
Post by mhx
Post by dxf
At the same time I also found
SET-PRECISION to be useful.
An example would be instructive.
Standard capacitor and resistor values are specified in terms
of significant digits.
Most will use F. for testing and debugging. In that case I would
prefer an F. based on PRECISION rather than PLACES. With the latter
the risk of a small f/p number printing as 0.0 is too high and thus
misleading.

Loading...