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

Support Infinity and NaN #6

Closed
ansstuff opened this issue Mar 15, 2019 · 1 comment
Closed

Support Infinity and NaN #6

ansstuff opened this issue Mar 15, 2019 · 1 comment

Comments

@ansstuff
Copy link

Thank you for the awesome library!

Having a representation of infinity would be really nice, as some algorithms (converted from floating-point math) sometimes turn a bit ugly, requiring hacks like boolean flags or additional checks.

E.g. for Fixed64 it could be:

public const long NaN = -9223372036854775808L;
public const long PositiveInfinity = 9223372036854775807L;
public const long NegativeInfinity = -9223372036854775807L;
public const long MinValue = -9223372036854775806L;
public const long MaxValue = 9223372036854775806L;

The main use for infinity is to guarantee there's never an overflow when dealing with unknown input, e.g. A + B <= PositiveInfinity; A + PositiveInfinity = PositiveInfinity.

Plus, infinity often serves as a perfect initial value for a FindMin algorithm. Of course you could use MaxValue instead, but sometimes you need to factor currentMin as input while searching, and the input needs to behave like infinity if nothing has been found yet.

Finally, together with NaN those constants should correctly cover most edge cases like Sqrt(<0), Log(0), Div(X, 0), Asin(>1), Tan(PiHalf), etc.

@petrikero
Copy link
Collaborator

Hi,

I agree that infinities and NaNs would be a nice feature, but I'm not sure if there's a way to implement them without significant performance penalties to the operations. Performance is one of the biggest priorities of the library, so we decided to omit support for such special cases. It's not perfect, but I don't really see a way around this, so I'm closing the issue as wontfix.

For FindMin() and similar, you can indeed use MinValue/MaxValue.

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

3 participants
@petrikero @ansstuff and others