overloadable inverse operator? ``` val i = 2 -i //...
# language-evolution
h
overloadable inverse operator?
Copy code
val i = 2
-i // -2
~i // 0.5

val M = Matrix.ofRows(vectorOf(4, 7), vectorOf(2, 6))
// [ 4 7
//   2 6 ]
-M
// [ -4 -7
//   -2 -6 ]
~M
// [  0.6 -0.7
//   -0.2  0.4 ]
👍 1
k
!
is still free!
Or you can use
1 /
too.
h
Yeah, but both operators I suggested exist in Kotlin and I like them a lot
In math
~
does actually mean inverse, too
k
~
doesn't exist in Kotlin yet?
h
It doesn't, hence why I think it could
At the same time I think it'd be cool to have an overload able ~= which would mean "about equal to", but that would conflict with the obvious inverseAssign of my higher priority wish
k
Haha that would be great for matlab users where
~=
is our
!=
h
Yeah, some languages like Matlab and lua use ~ as not where python uses it as inverse
e
Let’s take a look at what we already have.
a - b
is subtraction and
-b
is an additive inverse. Following this logic, because
a / b
denotes division, then multiplicative inverse should be denoted as
/b
(
operator unaryDiv
?).
🤔 1
👍 2
h
that's a fantastic suggestion as well
have there ever been any plans for using
~
in kotlin?
k
@Hullaballoonatic probably not, for the same reasons that
^
and
|
were excluded; they'd prefer to keep bitwise operators as words to improve clarity. If you could (re-)define them yourself, I'd bet over 50% of Kotlin codebases would re-introduce these as the bitwise operators. Regardless of my feelsings on this, I don't think JetBrains wants that