Re: Hex string literals (was Re: C23 thoughts and opinions)

Liste des GroupesRevenir à cl c 
Sujet : Re: Hex string literals (was Re: C23 thoughts and opinions)
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 18. Jun 2024, 11:28:01
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4rnfh$1a6m8$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Mozilla Thunderbird
On 18/06/2024 10:39, Michael S wrote:
On Mon, 17 Jun 2024 22:39:00 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
 
bart <bc@freeuk.com> writes:
>
AFAIK nobody uses octal anymore.
>
There are circumstances where being able to write constants
in octal is useful.  It also would be nice to be able to
write constants in base 4 and base 32 (because 5 is half
of 10).  I don't have occasion to prefer octal very often
but I'm glad it's there for those times when I do.
 Ada/VHDL permits any base from 2 to 16. They didn't go as far up as
32.
So did I for a while (in my language), for both integer and float constants. (Possibly influenced by languages such as Ada which allowed any base.)
But it was more of a novelty. In the end I decided they were just not useful enough, and simplified it so that only bases 2, 10 and 16 were supported.
Although output of integers in those bases is still possible (supported by code in a library, rather than within a compiler):
     print 81:"x3"           # displays 10000
(Output of floats is done via sprintf; the C library won't do those odd bases.)
While I did have it though, 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.

I would imagine that reading base 32 number would take time to become
accustomed.
My big-number /decimal/ library uses base 1000000000. That value fits into one i32 'limb'. But it doesn't need a billion distinct symbols, it just uses base-10 decimal as input and output.
As to why you can't use a similar idea for base-32, you'd have to look at what base-32 was used for. Certainly within source code, you could have a construct like:
     base32(31,31,31)     equivalent to 31*32**2 + 31*32 + 32 = 32767
A user running an application that promises base-32 arithmetic may expect something more exotic however.

Date Sujet#  Auteur
14 Jun 24 * Re: C23 thoughts and opinions56Keith Thompson
14 Jun 24 +* Re: C23 thoughts and opinions12bart
15 Jun 24 i`* Re: C23 thoughts and opinions11David Brown
15 Jun 24 i `* Re: C23 thoughts and opinions10bart
15 Jun 24 i  +* Re: C23 thoughts and opinions5Lawrence D'Oliveiro
16 Jun 24 i  i`* Re: C23 thoughts and opinions4bart
16 Jun 24 i  i +- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
16 Jun 24 i  i `* Re: C23 thoughts and opinions2Chris M. Thomasson
17 Jun 24 i  i  `- Re: C23 thoughts and opinions1Lawrence D'Oliveiro
16 Jun 24 i  `* Re: C23 thoughts and opinions4David Brown
16 Jun 24 i   `* Re: C23 thoughts and opinions3bart
17 Jun 24 i    +- Re: C23 thoughts and opinions1David Brown
17 Jun 24 i    `- Re: C23 thoughts and opinions1Michael S
15 Jun 24 +* Re: C23 thoughts and opinions3David Brown
15 Jun 24 i`* Re: C23 thoughts and opinions2Lawrence D'Oliveiro
16 Jun 24 i `- Re: C23 thoughts and opinions1David Brown
17 Jun 24 `* Hex string literals (was Re: C23 thoughts and opinions)40Keith Thompson
17 Jun 24  +* Re: Hex string literals (was Re: C23 thoughts and opinions)20David Brown
18 Jun 24  i+* Re: Hex string literals (was Re: C23 thoughts and opinions)18Keith Thompson
18 Jun 24  ii+* Re: Hex string literals (was Re: C23 thoughts and opinions)2Lawrence D'Oliveiro
18 Jun 24  iii`- Re: Hex string literals (was Re: C23 thoughts and opinions)1Keith Thompson
18 Jun 24  ii`* Re: Hex string literals (was Re: C23 thoughts and opinions)15David Brown
18 Jun 24  ii +* Re: Hex string literals (was Re: C23 thoughts and opinions)6Keith Thompson
19 Jun 24  ii i`* Re: Hex string literals (was Re: C23 thoughts and opinions)5David Brown
19 Jun 24  ii i `* Re: Hex string literals (was Re: C23 thoughts and opinions)4Kaz Kylheku
19 Jun 24  ii i  `* Re: Hex string literals (was Re: C23 thoughts and opinions)3Michael S
19 Jun 24  ii i   +- Re: Hex string literals (was Re: C23 thoughts and opinions)1bart
19 Jun 24  ii i   `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Michael S
19 Jun 24  ii `* Re: Hex string literals (was Re: C23 thoughts and opinions)8Lawrence D'Oliveiro
19 Jun 24  ii  +* Re: Hex string literals (was Re: C23 thoughts and opinions)6David Brown
21 Jun 24  ii  i`* Re: Hex string literals (was Re: C23 thoughts and opinions)5Lawrence D'Oliveiro
21 Jun 24  ii  i +* Re: Hex string literals (was Re: C23 thoughts and opinions)3David Brown
21 Jun 24  ii  i i`* Re: Hex string literals (was Re: C23 thoughts and opinions)2Lawrence D'Oliveiro
22 Jun 24  ii  i i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1David Brown
21 Jun 24  ii  i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1James Kuyper
19 Jun 24  ii  `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Keith Thompson
18 Jun 24  i`- Re: Hex string literals (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
17 Jun 24  +* Re: Hex string literals (was Re: C23 thoughts and opinions)5Richard Kettlewell
17 Jun 24  i+- Re: Hex string literals (was Re: C23 thoughts and opinions)1Richard Kettlewell
18 Jun 24  i`* Re: Hex string literals (was Re: C23 thoughts and opinions)3Keith Thompson
18 Jun 24  i +- Re: Hex string literals (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
18 Jun 24  i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Richard Kettlewell
17 Jun 24  `* Re: Hex string literals (was Re: C23 thoughts and opinions)14bart
18 Jun 24   +- Re: Hex string literals (was Re: C23 thoughts and opinions)1Keith Thompson
18 Jun 24   +* Re: Hex string literals (was Re: C23 thoughts and opinions)7Tim Rentsch
18 Jun 24   i`* Re: Hex string literals (was Re: C23 thoughts and opinions)6Michael S
18 Jun 24   i +* Re: Hex string literals (was Re: C23 thoughts and opinions)2bart
18 Jun 24   i i`- Re: Hex string literals (was Re: C23 thoughts and opinions)1Tim Rentsch
18 Jun 24   i +- Re: Hex string literals (was Re: C23 thoughts and opinions)1David Brown
18 Jun 24   i +- Re: Hex string literals (was Re: C23 thoughts and opinions)1Tim Rentsch
20 Jun 24   i `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro
18 Jun 24   `* Re: Hex string literals (was Re: C23 thoughts and opinions)5Kaz Kylheku
18 Jun 24    `* Re: Hex string literals (was Re: C23 thoughts and opinions)4David Brown
18 Jun 24     `* Re: Hex string literals (was Re: C23 thoughts and opinions)3Richard Harnden
18 Jun 24      +- Re: Hex string literals (was Re: C23 thoughts and opinions)1Richard Harnden
21 Jun 24      `- Re: Hex string literals (was Re: C23 thoughts and opinions)1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal