Path: csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Hex string literals (was Re: C23 thoughts and opinions)
Date: Tue, 18 Jun 2024 11:12:21 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86wmmmi0hm.fsf@linuxsc.com>
References: <87y18047jk.fsf@nosuchdomain.example.com> <87msoe1xxo.fsf@nosuchdomain.example.com> <87ikz11osy.fsf@nosuchdomain.example.com> <87plt8yxgn.fsf@nosuchdomain.example.com> <87cyp6zsen.fsf@nosuchdomain.example.com> <874jahznzt.fsf@nosuchdomain.example.com> <87v82b43h6.fsf@nosuchdomain.example.com> <87iky830v7.fsf_-_@nosuchdomain.example.com> <86v826kdxn.fsf@linuxsc.com> <20240618123940.00007f1a@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Tue, 18 Jun 2024 20:12:21 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d4aeba7b4aaab0d94b94221c1561c3e8"; logging-data="1536444"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cuC97z59J4vf9hV7j09+0yYmsFziHeuA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:9zR4Lk2s4H4iZ7/nyVbytfJFZP0= sha1:a8UfGioBxQAlVYqUeSY6EEAiwpU=
Xref: csiph.com comp.lang.c:386194
bart writes:
> [...] I noticed this strange discrepancy between
> between my hex floats and C's. In C, this value:
>
> 0x12.34p10
>
> has the decimal value 18640.0; why was that? It turns that this is:
>
> 18.203125 x 2 ** 10
>
> The main part is interpreted as actual hex; the exponent is in
> decimal, and exponent scaling is in binary bits. So THREE diferent
> bases are involved!
>
> In my scheme (which as I said worked for bases from 2 to 16), the
> 0x12.34p10 value would mean this:
>
> 18.203125 x 16 ** 16 ~= 3.58e20
>
> The same base is used for all parts, including the exponent, and the
> digits that are to be shifted. After all in decimal, 12.34e10 would
> mean:
>
> 12.34 x 10 ** 10 = 123400000000.0
>
> In my language, a base 5 version 5x12.34e10 (not valid below base 5)
> would mean this (I think, as I no longer have the compiler):
>
> 7.76 x 5 ** 5 = 24250.0
>
> This has a consistency lacking in C's hex floats.
The C hex float format has benefits that your format does not.