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

Inaccurate/misleading description of max in operators module (wrt. NaN comparison) #82

Open
abonie opened this issue Jun 6, 2022 · 0 comments

Comments

@abonie
Copy link

abonie commented Jun 6, 2022

Not sure if this is an error in documentation or purposeful omission, or perhaps a bug in fsharp.

Here max is described as

Maximum based on generic comparison

And here compare is described as

Generic comparison.

However, even though they kind of boil down to the same thing in implementation for most types, they do not specifically for floating point numbers. Moreover, if one defines a max function with compare, for example like this:

let max2 x y = if compare x y < 0 then y else x

Then max2 behaves differently than max with respect to NaN, e.g.:

> max2 1. nan;;
val it: float = 1.0

> max2 nan 1.;;
val it: float = 1.0

whereas

> max nan 1.;;
val it: float = nan

> max 1. nan;;
val it: float = nan

If this discrepancy in behavior is expected, then perhaps it should be documented?

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

1 participant