Calculating in other bases than 10

Liste des GroupesRevenir à cu shell 
Sujet : Calculating in other bases than 10
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell
Date : 18. Feb 2025, 10:59:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vp1lmt$1l73j$1@dont-email.me>
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
This was something that actually started elsewhere; first I noticed
the (token-)symmetric true predicate

  ((10#2==2#10))

i.e. that "2 cents (decimal) equals 10 cents (binary)". - Okay, that
started nice.


Then I wondered whether 2 and 10 are the only numbers that fulfill
the (informally written) equation

  ((n#m==m#n))             [*]

and wanted to automate such tests looping n, m through some numbers.

[*] Can that equation be proved or disproved for (m,n)-values other
than 2 and 10?


Quickly I noticed that  1#0  is not a legal number (in Kornshell), and
also 'bc' refuses that value

  ibase=1
  Runtime warning (func=(main), adr=3): ibase too small, set to 2

Of course math with only one digit 0 available makes not much sense,
but it didn't occur to me that base 1 is forbidden in the first place.
(I've certainly never pondered about that before.)


Continuing tests with 'bc'

  ibase=17
  Runtime warning (func=(main), adr=6): ibase too large, set to 16

And strange got this same error message for

  ibase=14
  Runtime warning (func=(main), adr=6): ibase too large, set to 16

I suppose no one cares about such details in exotic application cases.
(It's anyway a bug of only minor importance.)


BTW, Kornshell operates with bases up to 64 and I wonder what symbols
are used for that. Tests show that it depends on the base; for small
bases letters in caps are handled like lowercase letters, for larger
bases using caps matters, and for some bases we even get errors, e.g.

$ echo $((37#ff))
570
$ echo $((37#FF))
ksh: 37#FF: arithmetic syntax error

Looks like a bug to me.

Janis


Date Sujet#  Auteur
18 Feb 25 * Calculating in other bases than 105Janis Papanagnou
18 Feb 25 +- Re: Calculating in other bases than 101Janis Papanagnou
18 Feb 25 +* Re: Calculating in other bases than 102Christian Weisgerber
19 Feb 25 i`- Re: Calculating in other bases than 101Janis Papanagnou
19 Feb 25 `- Re: Calculating in other bases than 101Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal