[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Must "attempt to get length of a number value" be an error?
- From: Francisco Olarte <folarte@...>
- Date: Fri, 10 May 2019 12:50:47 +0200
On Thu, May 9, 2019 at 6:43 PM Dirk Laurie <dirk.laurie@gmail.com> wrote:
...
> My original motivation (not divulged in the post) was that invoking a
> function to get the absolute value of a number is really a very
> cumbersome way for something that can be done by the C ternary
> operator.Therefore I looked around for a unary operator not yet
> defined for type "number" and found that __len is the only candidate.
So, in C you use (x<0)?-x:x ( or a variation ) instead of just abs(3)
( or cousins ) ?
IMHO abs(x) is easier to read, hard to get wrong. I try to use it
(shorter easier than the ternary, and compilers optimize it quite well
since the nineties, IIRC microsoft dit it when generating 8086 code ).
And for just a little more keying ( # needs an special shitf in
spanish keyboards :-( ) I would prefer it in lua to # )
Also, if you like the ternary, isnt "(x<0) and -x or x" one of the
places where lua can simulate the ternary without problems?
Is # for abs the norm in some kind of math notation? ( really curious
on this, I haven't read much math lately )
Francisco Olarte.
- References:
- Must "attempt to get length of a number value" be an error?, Dirk Laurie
- Re: Must "attempt to get length of a number value" be an error?, Andrew Starks
- Re: Must "attempt to get length of a number value" be an error?, Coda Highland
- Re: Must "attempt to get length of a number value" be an error?, Philippe Verdy
- Re: Must "attempt to get length of a number value" be an error?, Coda Highland
- Re: Must "attempt to get length of a number value" be an error?, Philippe Verdy
- Re: Must "attempt to get length of a number value" be an error?, Coda Highland
- Re: Must "attempt to get length of a number value" be an error?, Philippe Verdy
- Re: Must "attempt to get length of a number value" be an error?, Coda Highland
- Re: Must "attempt to get length of a number value" be an error?, Philippe Verdy
- Re: Must "attempt to get length of a number value" be an error?, Coda Highland
- Re: Must "attempt to get length of a number value" be an error?, Philippe Verdy
- Re: Must "attempt to get length of a number value" be an error?, Coda Highland
- Re: Must "attempt to get length of a number value" be an error?, Dirk Laurie