Sujet : Re: Display Engineering Notation with SI Prefix
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 29. Aug 2024, 11:02:26
Autres entêtes
Organisation : Ausics - https://newsgroups.ausics.net
Message-ID : <66d04731$1@news.ausics.net>
References : 1
User-Agent : Mozilla Thunderbird
On 29/08/2024 1:32 am, dxf wrote:
\ 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
>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