Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Vax Vobiscum


devel / comp.lang.tcl / Re: Decimal Q numbers : fractional numbers represented by entier + number of fractional digits

SubjectAuthor
* Decimal Q numbers : fractional numbers represented by entier + number of fractioHarald Oehlmann
`* Re: Decimal Q numbers : fractional numbers represented by entier + number of fraRich
 `- Re: Decimal Q numbers : fractional numbers represented by entier + number of fraHarald Oehlmann

1
Decimal Q numbers : fractional numbers represented by entier + number of fractional digits

<ursf9i$16vln$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13027&group=comp.lang.tcl#13027

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Decimal Q numbers : fractional numbers represented by entier + number
of fractional digits
Date: Fri, 1 Mar 2024 12:48:02 +0100
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <ursf9i$16vln$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 1 Mar 2024 11:48:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="64c9927feff419283b373c7d5d34f073";
logging-data="1277623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GtUUO5RCOzvt1g+7Z2cTE"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HxUNvPPW2RTeLxen1YVgEq+z79A=
Content-Language: en-GB
 by: Harald Oehlmann - Fri, 1 Mar 2024 11:48 UTC

Dear TCL math enthusiasts,

I have programs to weight a minimum quantity using a scale.
Up to now, I used double math:

The scale has a certain resolution and returns a string like
"8.24 g". It always has 2 fractional digits ("24" in this example).

The minimum quantity is calculated from many factors and displayed to
the users.

What I did so far:
set weightIs "8.24 g"
set plan 6.8;set efficiency 1.2; set remainder 0.081
set weightShould [expr {$plan * $efficiency - $remainder}]
# the upper formular is arbitrary. It is just a calculation of multiple
factors
set weightIs [scan $weightIs "%f g"]
set weightShouldDisplay [format %.2f $weightShould]

if {$weightShould <= $weightIs} {#Ok}

The last comparision is the issue. If the user sees:
Minimum: 8.24
it really starts at something like: 8.235
So a remainder of 0.081 gives ok, but 0.078 gives not ok while
displaying the same number.

I also have an issue in documentation. The systems are validated and
should be consistent.

I also fear, that two doubles may have the same text representation. I
am not sure, if this may happen. Kevin Kenny has worked a lot on the
roundtrip, e.g. double->text->double gives the same result.

But is it true, that two doubles created from strings with same number
of digits are equal, if the strings are equal ?
set t1 [format %02f $d1]
set t2 [format %02f $d2]
set dt1 [scan $t1 %f]
set dt2 [scan $t2 %f]
if {$dt1 == $dt2} then $t1 eq $t2

So, I thought to use exact decimal quotational math. Each number is
represented by an entier and a fractional count

8.24 -> 824 2

(This is the q notation I know from embedded systems, but in decimal not
binary)

Limited math like multiplication, addition and comparison are possible.

Is this a good idea?
Is there already a library for this type of math?
I suppose, a custom TCL type may be defined, that would be weired ;-).

I know, something like this is used in accounting.
The rounding of operations is well defined in this case.
Banks are forced to take 3 fractional decimal digits for any operation.

Any idea welcome !

Thank you and take care,
Harald

Re: Decimal Q numbers : fractional numbers represented by entier + number of fractional digits

<urtlli$1fmu5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13029&group=comp.lang.tcl#13029

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Decimal Q numbers : fractional numbers represented by entier + number of fractional digits
Date: Fri, 1 Mar 2024 22:42:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <urtlli$1fmu5$1@dont-email.me>
References: <ursf9i$16vln$1@dont-email.me>
Injection-Date: Fri, 1 Mar 2024 22:42:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8ef4264d65e4b5af98262fada3f3b2a6";
logging-data="1563589"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ev4Bw7W7tUrt2fDD9vz8n"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:RdBRehGGY8aQfJ1ZomIMvGqXLI8=
 by: Rich - Fri, 1 Mar 2024 22:42 UTC

Harald Oehlmann <wortkarg3@yahoo.com> wrote:
> So, I thought to use exact decimal quotational math. Each number is
> represented by an entier and a fractional count
>
> 8.24 -> 824 2

> Is there already a library for this type of math?

Yes, Tcllib math::decimal
https://core.tcl-lang.org/tcllib/doc/tcllib-1-18/embedded/www/tcllib/files/modules/math/decimal.html

Re: Decimal Q numbers : fractional numbers represented by entier + number of fractional digits

<us2dh2$2k83b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13051&group=comp.lang.tcl#13051

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Decimal Q numbers : fractional numbers represented by entier +
number of fractional digits
Date: Sun, 3 Mar 2024 18:54:45 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <us2dh2$2k83b$1@dont-email.me>
References: <ursf9i$16vln$1@dont-email.me> <urtlli$1fmu5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Mar 2024 17:54:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa4901ae46499f23f04e7874db0c69bd";
logging-data="2760811"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Bvq+DcxMg8ofATFgqvV6y"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2pzyywOeT+XcE7AcEzru++p0+Z4=
In-Reply-To: <urtlli$1fmu5$1@dont-email.me>
Content-Language: en-GB
 by: Harald Oehlmann - Sun, 3 Mar 2024 17:54 UTC

Am 01.03.2024 um 23:42 schrieb Rich:
> Harald Oehlmann <wortkarg3@yahoo.com> wrote:
>> So, I thought to use exact decimal quotational math. Each number is
>> represented by an entier and a fractional count
>>
>> 8.24 -> 824 2
>
>> Is there already a library for this type of math?
>
> Yes, Tcllib math::decimal
> https://core.tcl-lang.org/tcllib/doc/tcllib-1-18/embedded/www/tcllib/files/modules/math/decimal.html
>

Thanks, Rich, that was exactly what I was looking for!
Great that you know all those details over many years!

Take care,
Harald

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor