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

min & max yield incorrect results with NaN #4696

Closed
vicuna opened this issue Jan 16, 2009 · 3 comments
Closed

min & max yield incorrect results with NaN #4696

vicuna opened this issue Jan 16, 2009 · 3 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jan 16, 2009

Original bug ID: 4696
Reporter: toton
Status: closed (set by @xavierleroy on 2009-03-28T17:12:27Z)
Resolution: not fixable
Priority: normal
Severity: major
Version: 3.10.0
Category: ~DO NOT USE (was: OCaml general)
Related to: #5781
Monitored by: @hcarty @dbuenzli @yakobowski

Bug description

min nan 1.;;

  • : float = 1.

min 1. nan;;

  • : float = nan

max nan 1.;;

  • : float = 1.

max 1. nan;;

All results should be NaN.
(Or at least docs should specify what is the intended behavior.)

@vicuna
Copy link
Author

vicuna commented Jan 29, 2009

Comment author: @dbuenzli

AFAIK IEEE 754-1985 doesn't specify a behaviour for min/max functions.

The recent IEEE 754-2008 [1] introduces minNum and maxNum (see 5.3.1). However when presented with a number and a quiet NaN these functions unconditionnaly return the number. So that would be the opposite of what the reporter proposes.

Best,

Daniel

[1] http://ieeexplore.ieee.org/servlet/opac?punumber=4610933

@vicuna
Copy link
Author

vicuna commented Jan 30, 2009

Comment author: dawidtoton

The documentation of Pervasives says simply:
"any operation with nan as argument returns nan as result"

I thought there is a bug in max & min, because their result depends on order of arguments. For me it is natural to assume that (max a b)=(max b a) if the documentation doesn't say otherwise.

However I understand that it is more important to have fast max & min operations than to handle NaNs in a specific way. So I reported this too hastily as a bug, this might be better seen as "documentation request".

@vicuna
Copy link
Author

vicuna commented Mar 28, 2009

Comment author: @xavierleroy

You expected min x NaN = NaN, but as D. Buenzli mentioned, other folks recommend min x NaN = x. In Caml, there is one additional difficulty, namely that min and max apply to composite data structures as well. So, what should be
min (x, NaN) (NaN, y), for example? I don't think a "best" behavior exists in this case, so the current implementation is as good (and as bad) as any other.

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

No branches or pull requests

1 participant