[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: __bshr vs __bshl
- From: "Soni \"They/Them\" L." <fakedme@...>
- Date: Sat, 7 Apr 2018 18:18:27 -0300
On 2018-04-07 05:34 PM, Albert Chan wrote:
On Apr 7, 2018, at 2:58 PM, Reinder Feenstra <firstname.lastname@example.org> wrote:
While implementing all meta methods in some glue code between Lua and
C++ I'd became curious why __bshr and __bshl both exist. For the
compare operators a smart trick is used so you don't need to implement
To make sure my glue code behaves the same as Lua I simply tried all
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
print(2 << -1)
print(2 >> 1)
This is legal in Lua, so why not only a __bshr meta method and call
this with a negative shift count for the << operator?
Same reason we have __sub operator (for convenience):
A - B = A + (-B)
A + (-B) is legal in Lua, so why not ...
Why have __add or __unm at all anyway
A + B == A - (0 - B)
-A == (0 - A)
Also why have __mul
A * B == A / (1 / B)
And so on.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.