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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! This macros module contains custom macros used primarily for testing.
//!
//! The macros here are used primarily in testing to assert numerical equality within specified tolerances. However, they can be used in other contexts as needed.
//!
//! # Examples
//!
//! ## assert_eq_precision
//!
//! This macro checks whether two numerical values are approximately equal within a specified precision (ratio).
//!
//! ```rust
//! use aero_atmos::assert_eq_precision;
//! let a: f64 = 100.0;
//! let b: f64 = 100.04;
//! let precision: f64 = 0.0005; // 0.05%
//! assert_eq_precision!(a, b, precision); // This will pass
//!
//! let c: f64 = 100.1;
//! // assert_eq_precision!(a, c, precision); // This will panic
//! ```
//!
//! ## assert_eq_sigfigs
//!
//! This macro checks whether two numerical values are approximately equal when rounded to a specified number of significant figures.
//!
//! ```rust
//! use aero_atmos::assert_eq_sigfigs;
//! assert_eq_sigfigs!(1.11111, 1.11222, 3); // <- will pass (1.11 == 1.11)
//! assert_eq_sigfigs!(1.1118, 1.1122, 4); // <- will pass (1.112 == 1.112)
//! ```
//!
//! ## dbg_sci
//!
//! This macro prints a numerical value, the expression that generates it (variable), in scientific notation for debugging purposes.
//! Additionally, it prints the file name and line number where the macro is invoked. Notably, this macro is only effective in debug builds; it
//! is not included in release builds.
//!
//! ```rust
//! use aero_atmos::dbg_sci;
//!
//! let x = 12345.6789;
//! dbg_sci!(x, 3); // prints something like "[src/main.rs:10] x = 1.234e4"
//! ```
/// Macro that checks whether two numerical values are approximately equal within a specified precision. Used in tests.
///
/// The specified precision is a ratio representing the maximum allowable relative difference between the two values.
///
/// # Arguments
/// - `left`: The first numerical value to compare.
/// - `right`: The second numerical value to compare.
/// - `precision`: The maximum allowable relative difference as a ratio (e.g., 0.01 for 1%).
///
/// # Examples
/// ```
/// use aero_atmos::assert_eq_precision;
/// let a: f64 = 100.0;
/// let b: f64 = 100.04;
/// let precision: f64 = 0.0005; // 0.05%
/// assert_eq_precision!(a, b, precision); // This will pass
///
/// let c: f64 = 100.1;
/// // assert_eq_precision!(a, c, precision); // This will panic
/// ```
/// Assert numbers rounded to a specified number of significant figures are equal. Used in tests.
///
/// This macro rounds both numbers to the specified number of significant figures
/// before comparing them for equality. The rounding will assume that the leftmost (greatest)
/// digit is the first significant figure.
///
/// # Arguments
/// - `left`: The first numerical value to compare.
/// - `right`: The second numerical value to compare.
/// - `sigfigs`: The number of significant figures to which both values should be rounded.
///
/// # Example
/// ```rust
/// use rust_decimal::prelude::*;
/// use aero_atmos::assert_eq_sigfigs;
///
/// assert_eq_sigfigs!(1.11111, 1.11222, 3); // <- will pass (1.11 == 1.11)
/// assert_eq_sigfigs!(1.1118, 1.1122, 4); // <- will pass (1.112 == 1.112)
/// ```
/// Debug macro for numerical values in scientific notation
///
/// Similar to `dbg!()` but prints a numeric value in scientific notation.
///
/// Just as `dbg!()` prints the file name and line number along with the value,
/// this macro prints the file name and line number along with the numeric value
/// in scientific notation.
///
/// The functionality of this macro only works in debug builds. In release builds, the macro does nothing.
///
/// # Arguments
/// * `val` - The numeric value to print in scientific notation.
/// * `decimal_places` - The number of decimal places to include in the scientific notation.
///
/// # Examples
/// ```
/// use aero_atmos::dbg_sci;
///
/// let x = 12345.6789;
/// dbg_sci!(x, 3); // prints something like "[src/main.rs:10] x = 1.235e4"
/// ```