• Calculating in other bases than 10

    From Janis Papanagnou@21:1/5 to All on Tue Feb 18 10:59:55 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Tue Feb 18 11:06:01 2025
    On 18.02.2025 10:59, Janis Papanagnou wrote:

    BTW, Kornshell operates with bases up to 64 and I wonder what symbols
    are used for that. [...]

    Experiments lead to: 0..9 a..z A..Z @ _
    (and it's also documented - doh!)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Weisgerber@21:1/5 to Janis Papanagnou on Tue Feb 18 13:13:05 2025
    On 2025-02-18, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    And strange got this same error message for

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

    Did you already set ibase before and that "14" is no longer decimal
    14?

    --
    Christian "naddy" Weisgerber naddy@mips.inka.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Christian Weisgerber on Wed Feb 19 01:19:29 2025
    On 18.02.2025 14:13, Christian Weisgerber wrote:
    On 2025-02-18, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    And strange got this same error message for

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

    Did you already set ibase before and that "14" is no longer decimal
    14?

    LOL - indeed. Thanks! - It didn't occur to me that setting the base
    for calculations will also affect the base for setting parameters.
    (Apart from the misleading error message it smells not like a good
    design but that explains it.)

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Wed Feb 19 06:46:54 2025
    On 18.02.2025 10:59, Janis Papanagnou wrote:
    [...]

    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.

    ...but it isn't! - As I've been pointed out base 37 just means that
    0-9, a-z, and A are accepted as digits, which of course makes sense.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)