>From the wikipedia article:

There are differences of opinion about the proper definition for the result of 
a numeric function <https://en.wikipedia.org/wiki/Subroutine> that receives a 
quiet NaN as input. One view is that the NaN should propagate to the output of 
the function in all cases to propagate the indication of an error. Another 
view, and the one taken by the ISO C99 <https://en.wikipedia.org/wiki/C99> and 
IEEE 754-2008 <https://en.wikipedia.org/wiki/IEEE_754-2008_revision> standards 
in general, is that if the function has multiple arguments and the output is 
uniquely determined by all the non-NaN inputs (including infinity), then that 
value should be the result.

Should Go be updated to follow IEEE 754-2008? [I assume currently it is 
following IEEE 754]

-- Bakul

> On Apr 26, 2021, at 11:28 PM, christoph...@gmail.com 
> <christophe.mees...@gmail.com> wrote:
> 
> It seam that C is wrong on this one and Go is right. The rationale is that a 
> NaN must propagate through operations so that we can detect problems (avoid 
> silent NaNs). See https://en.wikipedia.org/wiki/NaN 
> <https://en.wikipedia.org/wiki/NaN>
> 
> Thus any operation involving a NaN must return an NaN and this includes Max 
> and Min. 
>  
> Le jeudi 22 avril 2021 à 12:43:23 UTC+2, jesper.lou...@gmail.com a écrit :
> On Thu, Apr 22, 2021 at 11:54 AM 'Dan Kortschak' via golang-nuts 
> <golan...@googlegroups.com 
> <applewebdata://759E590D-D822-4243-8628-8AFCA54309DB>> wrote:
> 
> Does anyone know the reason for this? (Looking through other languages,
> the situation in general seems to be a mess).
> 
> 
> I looked at OCaml, which provides both variants:
> 
> Float.max : float -> float -> float
> Float.max_num : float -> float -> float
> 
> The `max` function includes NaNs in the computation, while `max_num` omits 
> them. Another important treatment the documentation mentions is `max -0.0 
> +0.0`.
> 
> I also looked at Matlab and R. They essentially provide ways to either 
> include the NaN or omit it from the computation, usually when you have a 
> vector of numbers where some of the numbers are unknown. I.e., they take 
> extra (optional) flags to their functions which tells you how to treat NaN 
> values.
> 
> The "pure" solution is clearly the one where NaN's yield a NaN. It is 
> isomorphic to a Monoid based on optional values with the NaN forming the 
> unknown element, often called the option-monoid or the maybe-monoid. Or said 
> otherwise: for any type a, where a is a monoid, so is 'option a':
> 
> forall a. Monoid a => Monoid (Option a)
> 
> Since the max function itself is a monoid with the neutral element taken as 
> the minimal value, -inf, we can thus "lift" NaN values on top and still have 
> some mathematical consistency.
> 
> But if you have an array of values, where some of them can be NaN, it is 
> probably smart to provide a function which filters the array of NaN values 
> and computes the remaining values. R provides the function `na.omit(..)` for 
> this. So do option types in languages such as OCaml or Haskell. Here, we are 
> not that concerned about what is sound from a formal point of view, but more 
> concerned with data cleanup before we start using the formality.
> 
> Max of two values is a special case. The generalized version takes an 
> array/vector of values and provides the maximum in the structure.
> 
> All of this leads me to conclude you probably want both variants in the end. 
> In some situations, it is better to include NaN values in the computation, 
> and in other situations, the right move is to omit/exclude them.
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com 
> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/9950a06b-1222-4543-b979-763f37516e2an%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/golang-nuts/9950a06b-1222-4543-b979-763f37516e2an%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CEEB3353-7441-4D50-84FA-61E6EFCC83F4%40iitbombay.org.

Reply via email to