Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #10033

Re: nested ternary discovery

From Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups comp.lang.awk
Subject Re: nested ternary discovery
Date 2025-10-13 04:30 +0200
Organization A noiseless patient Spider
Message-ID <10cho84$1tqtj$1@dont-email.me> (permalink)
References <10c866d$2lhr4$1@dont-email.me> <68e8bf90$0$671$14726298@news.sunsite.dk> <10cdgkc$nu0u$2@dont-email.me> <hbjoeklk2lcsa56c809dgn3aodh9r5rtb6@4ax.com>

Show all headers | View raw


On 13.10.2025 02:58, dave_thompson_2@comcast.net wrote:
> On Sat, 11 Oct 2025 11:55:57 -0000 (UTC), Mike Sanders
> <porkchop@invalid.foo> wrote:
> 
>> scale = (unit == "T") ? 1e12 :
>>         (unit == "B") ? 1e9  :
>>         (unit == "M") ? 1e6  :
>>         (unit == "K") ? 1e3  : 1
>>
> 
> scale = 1000 ^ index("KMBT",unit)

Nice hack. Just note that for the case of "no unit" - i.e. for an
empty string - index() returns 1, thus scale becomes 1000 and not
1 (as returned for other characters than the defined ones).

One problem with such arithmetic hacks is that it doesn't "scale"
nicely, e.g. when multi-character unit strings are involved, or
if the scales are not defined in regular forms. - Explicit 'if'
cascades, or string-keys in associative arrays are more robust.

Janis

Back to comp.lang.awk | Previous | NextPrevious in thread | Find similar


Thread

nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-09 11:27 +0000
  Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-09 17:09 +0200
    Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-10 19:38 +0000
    Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-11 11:46 +0000
      Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-11 16:58 +0000
        Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-12 03:47 +0000
      Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-12 01:54 +0200
        Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-12 03:49 +0000
  Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-09 16:59 +0000
  Re: nested ternary discovery mack@the-knife.org (Mack The Knife) - 2025-10-10 08:10 +0000
    Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-10 13:06 +0200
    Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-10 17:04 +0000
      Re: nested ternary discovery mack@the-knife.org (Mack The Knife) - 2025-10-11 17:44 +0000
        Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-11 18:46 +0000
          Re: nested ternary discovery mack@the-knife.org (Mack The Knife) - 2025-10-13 08:07 +0000
    Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-10 19:41 +0000
    Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-11 11:55 +0000
      Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-12 01:45 +0200
      Re: nested ternary discovery dave_thompson_2@comcast.net - 2025-10-12 20:58 -0400
        Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-13 04:30 +0200

csiph-web