fsharp / fsharp/fsharp-core-docs

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

未关闭
#82 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
没有语言数据
星标
37
派生
20
平均合并
6 分钟
30 天内合并 PR
1

描述

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?

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。