-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ^
from stdlib/math along with converters gives a match for types that aren't SomeNumber
#15033
Comments
I guess the right type would be type Multiplicable = concept x, y
x * y is type(x) or something like that. One can take powers of things that are not numbers, such as matrices or, as you mentioned, symbolic expressions |
Yeah that could make sense, but then we would have to rewrite the proc, right? Epically the case where y = 0. Then we would require the type to have some sort of x.zero/x.one or something, because x.default isn't always 0 or valid for that matter (take rationals for example: default is 0/0) |
But I think for custom types that one does most of the time want to implement |
Agreed, maybe it's easier like this |
The
^
proc in stdlib/math doesn't restrictT
to just floats and ints, and this gives problems when implementing^
for custom types involving converters. In my case, it's when both operands need to be converted that I stumble upon this.Example
Current Output
Expected Output
Possible Solution
The line that gives the error is this where it sets
result = 1
. But the proc's prototype isproc `^`*[T](x: T, y: Natural): T
which causes problems when T isn't int- or float-like and gives the above error message. A fix that worked for me is to narrow down what T can be:This makes sure that this proc is only called when it actually works with
T
.Additional Information
^
is meant to work with any type exceptSomeNumber
but if there is just close this.ExpressionType
and then I do also have aVariableType
for symbolic variables. When doing arithmetics with variables, they get converted automatically toExpressionType
. The problem arises when I'm using ints as well as variables. Both need to be converted, but the compiler finds a match for it so the conversion never happens.The text was updated successfully, but these errors were encountered: