2020-08-19 19:40:15 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// Copyright (c) 2015-2020 Zig Contributors
|
|
|
|
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
|
|
|
|
// The MIT license requires this copyright notice to be included in all copies
|
|
|
|
// and substantial portions of the software.
|
2019-03-02 13:46:04 -08:00
|
|
|
const std = @import("../std.zig");
|
2017-12-23 19:08:53 -08:00
|
|
|
const math = std.math;
|
2019-02-08 15:18:47 -08:00
|
|
|
const expect = std.testing.expect;
|
2018-10-26 11:59:58 -07:00
|
|
|
const maxInt = std.math.maxInt;
|
2017-06-16 01:26:10 -07:00
|
|
|
|
2019-04-30 23:15:57 -07:00
|
|
|
/// Returns whether x is a nan.
|
2020-07-11 04:09:04 -07:00
|
|
|
pub fn isNan(x: anytype) bool {
|
2019-04-05 06:47:52 -07:00
|
|
|
return x != x;
|
2017-06-16 01:26:10 -07:00
|
|
|
}
|
|
|
|
|
2019-04-30 23:15:57 -07:00
|
|
|
/// Returns whether x is a signalling nan.
|
2020-07-11 04:09:04 -07:00
|
|
|
pub fn isSignalNan(x: anytype) bool {
|
2019-04-30 23:15:57 -07:00
|
|
|
// Note: A signalling nan is identical to a standard nan right now but may have a different bit
|
|
|
|
// representation in the future when required.
|
2017-12-21 21:50:30 -08:00
|
|
|
return isNan(x);
|
2017-06-20 04:01:04 -07:00
|
|
|
}
|
|
|
|
|
2017-06-19 11:36:33 -07:00
|
|
|
test "math.isNan" {
|
2019-02-08 15:18:47 -08:00
|
|
|
expect(isNan(math.nan(f16)));
|
|
|
|
expect(isNan(math.nan(f32)));
|
|
|
|
expect(isNan(math.nan(f64)));
|
2019-02-13 02:27:23 -08:00
|
|
|
expect(isNan(math.nan(f128)));
|
2019-11-06 20:25:57 -08:00
|
|
|
expect(!isNan(@as(f16, 1.0)));
|
|
|
|
expect(!isNan(@as(f32, 1.0)));
|
|
|
|
expect(!isNan(@as(f64, 1.0)));
|
|
|
|
expect(!isNan(@as(f128, 1.0)));
|
2017-06-16 01:26:10 -07:00
|
|
|
}
|