Skip to content
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

Why does math.sign return the input type? #208

Open
HellGate94 opened this issue Dec 1, 2021 · 2 comments
Open

Why does math.sign return the input type? #208

HellGate94 opened this issue Dec 1, 2021 · 2 comments

Comments

@HellGate94
Copy link

I noticed this difference when working on my own (mostly) compatible library.
This is different than the System.Math and hlsl definition where they always return an integer type.

Any particular reason why this change is done?

@unpacklo
Copy link
Collaborator

unpacklo commented Dec 1, 2021

This may have been a mistake if the return type is different from the HLSL version. Usually, I prefer to return the same type as the input for functions like this if there's a reasonable chance that someone would use the returned value as a part of the computation. So for instance, if you wanted to do x * sign(x) or something similar.

Are you running into a problem due to the fact that the return type is different from the other versions?

@HellGate94
Copy link
Author

HellGate94 commented Dec 2, 2021

I guessed the reason has to do with preventing type conversion, but was surprised that it is worth changing the default definition.

Is it currently causing problems?
Not really.

Could it cause problems?
When doing math and floating point comparisons maybe?
Could cause implicit type conversions int * sign(float) => float

The hlsl definition:

Name Template Type Component Type Size
x scalar, vector, or matrix float, int any
ret same as input x int same dimension(s) as input x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants