-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnum.jule
More file actions
30 lines (26 loc) · 978 Bytes
/
num.jule
File metadata and controls
30 lines (26 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2025 mertcandav.
// Use of this source code is governed by a BSD 3-Clause
// license that can be found in the LICENSE file.
use "std/math"
// Reports whether two values a and b are considered equal, allowing NaNs.
fn Equal(a: f64, b: f64): bool {
ret a == b || math::IsNaN(a) && math::IsNaN(b)
}
// Reports whether two values a and b are considered same.
// It returns true if both are NaN (Not a Number), or if they are exactly equal
// including matching their sign bits (distinguishing +0 and -0).
// If both are NaN, if guarantees payload equality for the quiet-NaNs.
fn Same(a: f64, b: f64): bool {
match {
| math::IsNaN(a) && math::IsNaN(b):
// Inline implementation of the NaNPayload for a and b.
ret math::F64bits(a)&^nanMask == math::F64bits(b)&^nanMask
| a == b:
ret math::Signbit(a) == math::Signbit(b)
}
ret false
}
// Clamps x to the range [min, max].
fn Clamp(x: f64, min: f64, max: f64): f64 {
ret math::Max(min, math::Min(x, max))
}