[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: $((expr)) allows the hexadecimal constant "0x"
From: |
Steffen Nurpmeso |
Subject: |
Re: $((expr)) allows the hexadecimal constant "0x" |
Date: |
Wed, 13 Dec 2023 00:31:05 +0100 |
User-agent: |
s-nail v14.9.24-575-g511215237e |
Koichi Murase wrote in
<CAFLRLk_btwbPzzTRMp9OL21-2AG7i9KAXiXC7tQocSay3VKaJw@mail.gmail.com>:
|2023年12月10日(日) 15:58 Koichi Murase <myoga.murase@gmail.com>:
|> 2023年12月10日(日) 14:13 Martin D Kealey <martin@kurahaupo.gen.nz>:
...
|> I'm not a big fan of `10#[-+]digits' and invalidating `10#' either
...
|I checked the behaviors of different shells because I was interested
|in them. They seem to vary more than I expected.
|
|| $((10#)) | $((2*10#-1)) | $((2*10#- 1))
|----------|----------|--------------|---------------
|bash-5.0 | 0 | -1 | -1
|bash-5.1 | error | error | error
|ksh93u | 0 | -2 | -1
|ksh93v | error | error | error
|mksh | 0 | -1 | -1
|zsh | 0 | -2 | error
|
|ksh93u is tested with "Version AJM 93u+m/1.0.3 2022-08-25" and
|"Version AJM 93u+ 2012-08-01". ksh93v is tested with "Version A
|2020.0.0" (strictly speaking, this is not 93v but developed based on
|93v). $((2*10# -1)) was the same as $((2*10#-1)). $((2*10# - 1)) was
|the same as $((2*10#- 1)).
It is totally off-topic, but please let me add the results for the
MUA i maintain (ie the next version that includes $(()), but the
cold is now over a year old):
? echo $((10#))
.. Bad $(()) substitution: unknown operator: 10#: stop near: 10#
Derived from the ISO C standard, i thought when 0x is 0 rest x,
then that is 10 rest #, and that is not a valid arithmetic
expression. $((10# 8)) would echo "8" for my one, as below.
? echo $((2*10#-1))
-2
? echo $((2*10#- 1))
..: Bad $(()) substitution: unknown operator: 2*10#- 1: stop near: 10#- 1
This is because field padding is not supported: "- 1" is not
a negative value, but a hyphen-minus, a space, and a positive
decimal.
? echo $((2*10# -1))
-2
As above, $(()) uses a convenience mode
/*! Relaxed \a{base} 0 convenience: if the input used \c{BASE#number} number
sign syntax,
* then the scan will be restarted anew with the given base.
* Like this an UI can be permissive and support \c{s=' -008'; eval 10#\$s}
out of the box
* (it would require a lot of logic otherwise). */
su_IDEC_MODE_BASE0_NUMSIG_RESCAN = 1u<<3,
I thought this would be a good idea, and i like it in practice.
Here it is local to $(()) in addition.
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
|
| Only in December: lightful Dubai COP28 Narendra Modi quote:
| A small part of humanity has ruthlessly exploited nature.
| But the entire humanity is bearing the cost of it,
| especially the inhabitants of the Global South.
| The selfishness of a few will lead the world into darkness,
| not just for themselves but for the entire world.
| [Christians might think of Revelation 11:18
| The nations were angry, and your wrath has come[.]
| [.]for destroying those who destroy the earth.
| But i find the above more kind, and much friendlier]
Re: $((expr)) allows the hexadecimal constant "0x", Chet Ramey, 2023/12/11
Re: $((expr)) allows the hexadecimal constant "0x", Chet Ramey, 2023/12/11