EquateNaNs returns a [cmp.Comparer] option that determines float32 and float64 NaN values to be equal. EquateNaNs can be used in conjunction with [EquateApprox].
()
| 79 | // |
| 80 | // EquateNaNs can be used in conjunction with [EquateApprox]. |
| 81 | func EquateNaNs() cmp.Option { |
| 82 | return cmp.Options{ |
| 83 | cmp.FilterValues(areNaNsF64s, cmp.Comparer(equateAlways)), |
| 84 | cmp.FilterValues(areNaNsF32s, cmp.Comparer(equateAlways)), |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func areNaNsF64s(x, y float64) bool { |
| 89 | return math.IsNaN(x) && math.IsNaN(y) |