fsharp / fsharp/fsharp-core-docs

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

Open
#82 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
37
Forks
20
Avg merge
6m
Merged PRs (30d)
1

Description

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

[Here](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-operators.html#max) `max` is described as

> Maximum based on generic comparison

And [here](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-operators.html#compare) `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:

```fsharp
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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Review the generated documentation entries for max and compare linked in the issue, then reproduce the shown NaN examples to confirm the behavior. Determine whether the discrepancy is expected; done means the documentation accurately explains max's NaN behavior or the issue is shown to be a bug requiring a separate fix.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.