siderust-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +166 -0
- package/.gitmodules +9 -0
- package/CHANGELOG.md +26 -0
- package/LICENSE +661 -0
- package/README.md +138 -0
- package/package.json +12 -0
- package/qtty-js/.github/workflows/ci.yml +151 -0
- package/qtty-js/.gitmodules +3 -0
- package/qtty-js/CHANGELOG.md +31 -0
- package/qtty-js/LICENSE +661 -0
- package/qtty-js/README.md +132 -0
- package/qtty-js/package.json +20 -0
- package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
- package/qtty-js/qtty/CHANGELOG.md +120 -0
- package/qtty-js/qtty/Cargo.lock +1462 -0
- package/qtty-js/qtty/Cargo.toml +12 -0
- package/qtty-js/qtty/LICENSE +661 -0
- package/qtty-js/qtty/README.md +9 -0
- package/qtty-js/qtty/qtty/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty/README.md +8 -0
- package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
- package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
- package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
- package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
- package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
- package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
- package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
- package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
- package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
- package/qtty-js/qtty/qtty/src/f32.rs +108 -0
- package/qtty-js/qtty/qtty/src/f64.rs +30 -0
- package/qtty-js/qtty/qtty/src/i128.rs +111 -0
- package/qtty-js/qtty/qtty/src/i16.rs +111 -0
- package/qtty-js/qtty/qtty/src/i32.rs +111 -0
- package/qtty-js/qtty/qtty/src/i64.rs +111 -0
- package/qtty-js/qtty/qtty/src/i8.rs +111 -0
- package/qtty-js/qtty/qtty/src/lib.rs +238 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
- package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
- package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
- package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
- package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
- package/qtty-js/qtty/qtty-core/README.md +8 -0
- package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
- package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
- package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
- package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
- package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
- package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
- package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
- package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
- package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
- package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
- package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
- package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
- package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
- package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
- package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
- package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
- package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
- package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
- package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
- package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
- package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
- package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
- package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
- package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
- package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
- package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
- package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
- package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
- package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
- package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
- package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
- package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
- package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
- package/qtty-js/qtty/qtty-derive/README.md +8 -0
- package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
- package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
- package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
- package/qtty-js/qtty/qtty-ffi/README.md +9 -0
- package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
- package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
- package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
- package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
- package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
- package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
- package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
- package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
- package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
- package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
- package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
- package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
- package/qtty-js/qtty-node/.prettierignore +6 -0
- package/qtty-js/qtty-node/.prettierrc.json +6 -0
- package/qtty-js/qtty-node/README.md +250 -0
- package/qtty-js/qtty-node/c8.config.json +11 -0
- package/qtty-js/qtty-node/eslint.config.js +31 -0
- package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
- package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
- package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
- package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
- package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
- package/qtty-js/qtty-node/index.d.ts +219 -0
- package/qtty-js/qtty-node/index.js +323 -0
- package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
- package/qtty-js/qtty-node/lib/Quantity.js +151 -0
- package/qtty-js/qtty-node/lib/backend.js +25 -0
- package/qtty-js/qtty-node/native.cjs +306 -0
- package/qtty-js/qtty-node/package-lock.json +3223 -0
- package/qtty-js/qtty-node/package.json +70 -0
- package/qtty-js/qtty-node/units.d.ts +299 -0
- package/qtty-js/qtty-node/units.js +210 -0
- package/qtty-js/qtty-web/Cargo.lock +767 -0
- package/qtty-js/qtty-web/Cargo.toml +21 -0
- package/qtty-js/qtty-web/index.d.ts +140 -0
- package/qtty-js/qtty-web/index.js +20 -0
- package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
- package/qtty-js/qtty-web/lib/Quantity.js +75 -0
- package/qtty-js/qtty-web/lib/backend.js +80 -0
- package/qtty-js/qtty-web/package.json +45 -0
- package/qtty-js/qtty-web/src/lib.rs +111 -0
- package/qtty-js/scripts/ci.sh +73 -0
- package/scripts/ci.sh +123 -0
- package/siderust-core/Cargo.lock +787 -0
- package/siderust-core/Cargo.toml +18 -0
- package/siderust-core/DEDUPLICATION.md +124 -0
- package/siderust-core/src/body.rs +120 -0
- package/siderust-core/src/events.rs +184 -0
- package/siderust-core/src/lib.rs +20 -0
- package/siderust-core/src/observer.rs +55 -0
- package/siderust-core/src/position.rs +213 -0
- package/siderust-node/.prettierignore +7 -0
- package/siderust-node/.prettierrc.json +6 -0
- package/siderust-node/Cargo.lock +906 -0
- package/siderust-node/Cargo.toml +29 -0
- package/siderust-node/README.md +109 -0
- package/siderust-node/__test__/index.test.mjs +248 -0
- package/siderust-node/build.rs +5 -0
- package/siderust-node/c8.config.json +3 -0
- package/siderust-node/eslint.config.js +31 -0
- package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
- package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
- package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
- package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
- package/siderust-node/examples/05_target_tracking.mjs +22 -0
- package/siderust-node/examples/06_night_events.mjs +18 -0
- package/siderust-node/examples/07_moon_properties.mjs +21 -0
- package/siderust-node/examples/08_solar_system.mjs +19 -0
- package/siderust-node/examples/09_star_observability.mjs +22 -0
- package/siderust-node/examples/10_time_periods.mjs +9 -0
- package/siderust-node/examples/11_serialization.mjs +31 -0
- package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
- package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
- package/siderust-node/index.d.ts +623 -0
- package/siderust-node/index.js +79 -0
- package/siderust-node/lib/Observer.js +112 -0
- package/siderust-node/lib/Star.js +118 -0
- package/siderust-node/lib/backend.js +63 -0
- package/siderust-node/lib/wrappers.js +566 -0
- package/siderust-node/main.js +20 -0
- package/siderust-node/native.cjs +360 -0
- package/siderust-node/package-lock.json +3261 -0
- package/siderust-node/package.json +71 -0
- package/siderust-node/src/body.rs +74 -0
- package/siderust-node/src/coordinates.rs +372 -0
- package/siderust-node/src/ephemeris.rs +462 -0
- package/siderust-node/src/events.rs +577 -0
- package/siderust-node/src/lib.rs +43 -0
- package/siderust-node/src/observer.rs +132 -0
- package/siderust-node/src/phase.rs +218 -0
- package/siderust-node/src/position.rs +292 -0
- package/siderust-node/src/star.rs +200 -0
- package/siderust-web/Cargo.lock +855 -0
- package/siderust-web/Cargo.toml +34 -0
- package/siderust-web/README.md +100 -0
- package/siderust-web/__test__/index.test.mjs +118 -0
- package/siderust-web/examples/github-pages/README.md +31 -0
- package/siderust-web/examples/github-pages/index.html +135 -0
- package/siderust-web/index.d.ts +311 -0
- package/siderust-web/index.js +66 -0
- package/siderust-web/lib/Observer.js +103 -0
- package/siderust-web/lib/Star.js +116 -0
- package/siderust-web/lib/backend.js +400 -0
- package/siderust-web/lib/wrappers.js +512 -0
- package/siderust-web/package.json +55 -0
- package/siderust-web/src/body.rs +69 -0
- package/siderust-web/src/coordinates.rs +302 -0
- package/siderust-web/src/ephemeris.rs +456 -0
- package/siderust-web/src/events.rs +520 -0
- package/siderust-web/src/lib.rs +51 -0
- package/siderust-web/src/observer.rs +117 -0
- package/siderust-web/src/phase.rs +190 -0
- package/siderust-web/src/position.rs +291 -0
- package/siderust-web/src/star.rs +178 -0
- package/tempoch-js/.github/workflows/ci.yml +142 -0
- package/tempoch-js/.gitmodules +3 -0
- package/tempoch-js/CHANGELOG.md +25 -0
- package/tempoch-js/LICENSE +661 -0
- package/tempoch-js/README.md +126 -0
- package/tempoch-js/package.json +20 -0
- package/tempoch-js/scripts/ci.sh +73 -0
- package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
- package/tempoch-js/tempoch/CHANGELOG.md +82 -0
- package/tempoch-js/tempoch/Cargo.lock +947 -0
- package/tempoch-js/tempoch/Cargo.toml +3 -0
- package/tempoch-js/tempoch/LICENSE +661 -0
- package/tempoch-js/tempoch/README.md +76 -0
- package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
- package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
- package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
- package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
- package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
- package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
- package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
- package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
- package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
- package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
- package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
- package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
- package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
- package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
- package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
- package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
- package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
- package/tempoch-js/tempoch-node/.prettierignore +6 -0
- package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
- package/tempoch-js/tempoch-node/Cargo.lock +496 -0
- package/tempoch-js/tempoch-node/Cargo.toml +29 -0
- package/tempoch-js/tempoch-node/README.md +265 -0
- package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
- package/tempoch-js/tempoch-node/build.rs +5 -0
- package/tempoch-js/tempoch-node/c8.config.json +3 -0
- package/tempoch-js/tempoch-node/eslint.config.js +31 -0
- package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
- package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
- package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
- package/tempoch-js/tempoch-node/index.d.ts +280 -0
- package/tempoch-js/tempoch-node/index.js +32 -0
- package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
- package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
- package/tempoch-js/tempoch-node/lib/Period.js +133 -0
- package/tempoch-js/tempoch-node/lib/backend.js +38 -0
- package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
- package/tempoch-js/tempoch-node/native.cjs +317 -0
- package/tempoch-js/tempoch-node/package-lock.json +3223 -0
- package/tempoch-js/tempoch-node/package.json +56 -0
- package/tempoch-js/tempoch-node/src/lib.rs +573 -0
- package/tempoch-js/tempoch-web/Cargo.toml +23 -0
- package/tempoch-js/tempoch-web/index.d.ts +95 -0
- package/tempoch-js/tempoch-web/index.js +27 -0
- package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
- package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
- package/tempoch-js/tempoch-web/lib/Period.js +121 -0
- package/tempoch-js/tempoch-web/lib/backend.js +118 -0
- package/tempoch-js/tempoch-web/package.json +46 -0
- package/tempoch-js/tempoch-web/src/lib.rs +184 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
//! Tests for f64 Real trait methods (coverage for scalar.rs).
|
|
2
|
+
|
|
3
|
+
use qtty_core::scalar::{Real, Scalar, Transcendental};
|
|
4
|
+
|
|
5
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
6
|
+
// Scalar methods
|
|
7
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
#[test]
|
|
10
|
+
fn f64_rem_euclid_positive() {
|
|
11
|
+
assert_eq!(Scalar::rem_euclid(10.0_f64, 3.0), 1.0);
|
|
12
|
+
assert_eq!(Scalar::rem_euclid(7.0_f64, 2.5), 2.0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#[test]
|
|
16
|
+
fn f64_rem_euclid_negative() {
|
|
17
|
+
let r = Scalar::rem_euclid(-10.0_f64, 3.0);
|
|
18
|
+
assert!((r - 2.0).abs() < 1e-15);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
22
|
+
// Real methods
|
|
23
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
#[test]
|
|
26
|
+
fn f64_signum() {
|
|
27
|
+
assert_eq!(Real::signum(5.0_f64), 1.0);
|
|
28
|
+
assert_eq!(Real::signum(-5.0_f64), -1.0);
|
|
29
|
+
// IEEE 754: signum(+0.0) is not 0, but implementation-defined
|
|
30
|
+
// Rust's f64::signum(0.0) returns 1.0
|
|
31
|
+
assert_eq!(Real::signum(0.0_f64), 1.0);
|
|
32
|
+
assert!(Real::signum(f64::NAN).is_nan());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[test]
|
|
36
|
+
fn f64_is_finite() {
|
|
37
|
+
assert!(Real::is_finite(42.0_f64));
|
|
38
|
+
assert!(!Real::is_finite(f64::INFINITY));
|
|
39
|
+
assert!(!Real::is_finite(f64::NEG_INFINITY));
|
|
40
|
+
assert!(!Real::is_finite(f64::NAN));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[test]
|
|
44
|
+
fn f64_is_nan() {
|
|
45
|
+
assert!(Real::is_nan(f64::NAN));
|
|
46
|
+
assert!(!Real::is_nan(0.0_f64));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[test]
|
|
50
|
+
fn f64_is_infinite() {
|
|
51
|
+
assert!(Real::is_infinite(f64::INFINITY));
|
|
52
|
+
assert!(Real::is_infinite(f64::NEG_INFINITY));
|
|
53
|
+
assert!(!Real::is_infinite(42.0_f64));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#[test]
|
|
57
|
+
fn f64_mul_add() {
|
|
58
|
+
let result = Real::mul_add(2.0_f64, 3.0, 4.0);
|
|
59
|
+
assert!((result - 10.0).abs() < 1e-15);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[test]
|
|
63
|
+
fn f64_floor() {
|
|
64
|
+
assert_eq!(Real::floor(3.7_f64), 3.0);
|
|
65
|
+
assert_eq!(Real::floor(-3.7_f64), -4.0);
|
|
66
|
+
assert_eq!(Real::floor(5.0_f64), 5.0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[test]
|
|
70
|
+
fn f64_ceil() {
|
|
71
|
+
assert_eq!(Real::ceil(3.2_f64), 4.0);
|
|
72
|
+
assert_eq!(Real::ceil(-3.2_f64), -3.0);
|
|
73
|
+
assert_eq!(Real::ceil(5.0_f64), 5.0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[test]
|
|
77
|
+
fn f64_round() {
|
|
78
|
+
assert_eq!(Real::round(3.5_f64), 4.0);
|
|
79
|
+
assert_eq!(Real::round(3.4_f64), 3.0);
|
|
80
|
+
assert_eq!(Real::round(-3.5_f64), -4.0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[test]
|
|
84
|
+
fn f64_trunc() {
|
|
85
|
+
assert_eq!(Real::trunc(3.9_f64), 3.0);
|
|
86
|
+
assert_eq!(Real::trunc(-3.9_f64), -3.0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[test]
|
|
90
|
+
fn f64_fract() {
|
|
91
|
+
let f = Real::fract(3.75_f64);
|
|
92
|
+
assert!((f - 0.75).abs() < 1e-15);
|
|
93
|
+
let f = Real::fract(-3.75_f64);
|
|
94
|
+
assert!((f - (-0.75)).abs() < 1e-15);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[test]
|
|
98
|
+
fn f64_powf() {
|
|
99
|
+
let r = Real::powf(2.0_f64, 10.0);
|
|
100
|
+
assert!((r - 1024.0).abs() < 1e-10);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#[test]
|
|
104
|
+
fn f64_powi() {
|
|
105
|
+
let r = Real::powi(2.0_f64, 10);
|
|
106
|
+
assert!((r - 1024.0).abs() < 1e-10);
|
|
107
|
+
let r = Real::powi(3.0_f64, 0);
|
|
108
|
+
assert!((r - 1.0).abs() < 1e-15);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[test]
|
|
112
|
+
fn f64_sqrt() {
|
|
113
|
+
assert!((Real::sqrt(16.0_f64) - 4.0).abs() < 1e-15);
|
|
114
|
+
assert!((Real::sqrt(2.0_f64) - core::f64::consts::SQRT_2).abs() < 1e-15);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[test]
|
|
118
|
+
fn f64_cbrt() {
|
|
119
|
+
assert!((Real::cbrt(27.0_f64) - 3.0).abs() < 1e-15);
|
|
120
|
+
assert!((Real::cbrt(-8.0_f64) - (-2.0)).abs() < 1e-15);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
#[test]
|
|
124
|
+
fn f64_ln() {
|
|
125
|
+
assert!((Real::ln(1.0_f64)).abs() < 1e-15);
|
|
126
|
+
assert!((Real::ln(core::f64::consts::E) - 1.0).abs() < 1e-15);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[test]
|
|
130
|
+
fn f64_log10() {
|
|
131
|
+
assert!((Real::log10(100.0_f64) - 2.0).abs() < 1e-15);
|
|
132
|
+
assert!((Real::log10(1.0_f64)).abs() < 1e-15);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#[test]
|
|
136
|
+
fn f64_log2() {
|
|
137
|
+
assert!((Real::log2(8.0_f64) - 3.0).abs() < 1e-15);
|
|
138
|
+
assert!((Real::log2(1.0_f64)).abs() < 1e-15);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[test]
|
|
142
|
+
fn f64_log() {
|
|
143
|
+
// log base 10 of 1000
|
|
144
|
+
assert!((Real::log(1000.0_f64, 10.0) - 3.0).abs() < 1e-12);
|
|
145
|
+
// log base 2 of 16
|
|
146
|
+
assert!((Real::log(16.0_f64, 2.0) - 4.0).abs() < 1e-12);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#[test]
|
|
150
|
+
fn f64_exp() {
|
|
151
|
+
assert!((Real::exp(0.0_f64) - 1.0).abs() < 1e-15);
|
|
152
|
+
assert!((Real::exp(1.0_f64) - core::f64::consts::E).abs() < 1e-14);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#[test]
|
|
156
|
+
fn f64_exp2() {
|
|
157
|
+
assert!((Real::exp2(0.0_f64) - 1.0).abs() < 1e-15);
|
|
158
|
+
assert!((Real::exp2(10.0_f64) - 1024.0).abs() < 1e-10);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#[test]
|
|
162
|
+
fn f64_hypot() {
|
|
163
|
+
assert!((Real::hypot(3.0_f64, 4.0) - 5.0).abs() < 1e-15);
|
|
164
|
+
assert!((Real::hypot(5.0_f64, 12.0) - 13.0).abs() < 1e-13);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
168
|
+
// Real constants
|
|
169
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
170
|
+
|
|
171
|
+
#[test]
|
|
172
|
+
fn f64_real_constants() {
|
|
173
|
+
assert!((f64::PI - core::f64::consts::PI).abs() < 1e-15);
|
|
174
|
+
assert!((f64::TAU - core::f64::consts::TAU).abs() < 1e-15);
|
|
175
|
+
assert!((f64::E - core::f64::consts::E).abs() < 1e-15);
|
|
176
|
+
assert!(f64::INFINITY.is_infinite());
|
|
177
|
+
assert!(f64::NEG_INFINITY.is_infinite());
|
|
178
|
+
assert!(f64::NAN.is_nan());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#[test]
|
|
182
|
+
fn f64_from_to_f64_identity() {
|
|
183
|
+
let val = 123.456_f64;
|
|
184
|
+
assert_eq!(f64::from_f64(val), val);
|
|
185
|
+
assert_eq!(val.to_f64(), val);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
189
|
+
// Transcendental methods — f64
|
|
190
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
191
|
+
|
|
192
|
+
#[test]
|
|
193
|
+
fn f64_sin() {
|
|
194
|
+
let pi = core::f64::consts::PI;
|
|
195
|
+
assert!((Transcendental::sin(0.0_f64)).abs() < 1e-15);
|
|
196
|
+
assert!((Transcendental::sin(pi / 2.0) - 1.0).abs() < 1e-15);
|
|
197
|
+
assert!((Transcendental::sin(pi)).abs() < 1e-15);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
#[test]
|
|
201
|
+
fn f64_cos() {
|
|
202
|
+
let pi = core::f64::consts::PI;
|
|
203
|
+
assert!((Transcendental::cos(0.0_f64) - 1.0).abs() < 1e-15);
|
|
204
|
+
assert!((Transcendental::cos(pi / 2.0)).abs() < 1e-15);
|
|
205
|
+
assert!((Transcendental::cos(pi) + 1.0).abs() < 1e-15);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#[test]
|
|
209
|
+
fn f64_tan() {
|
|
210
|
+
let pi = core::f64::consts::PI;
|
|
211
|
+
assert!((Transcendental::tan(0.0_f64)).abs() < 1e-15);
|
|
212
|
+
assert!((Transcendental::tan(pi / 4.0) - 1.0).abs() < 1e-14);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[test]
|
|
216
|
+
fn f64_sin_cos() {
|
|
217
|
+
let pi = core::f64::consts::PI;
|
|
218
|
+
let (s, c) = Transcendental::sin_cos(pi / 6.0_f64);
|
|
219
|
+
assert!((s - 0.5).abs() < 1e-15);
|
|
220
|
+
assert!((c - (3.0_f64).sqrt() / 2.0).abs() < 1e-15);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#[test]
|
|
224
|
+
fn f64_asin() {
|
|
225
|
+
assert!((Transcendental::asin(0.5_f64) - core::f64::consts::FRAC_PI_6).abs() < 1e-15);
|
|
226
|
+
assert!((Transcendental::asin(1.0_f64) - core::f64::consts::FRAC_PI_2).abs() < 1e-15);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
#[test]
|
|
230
|
+
fn f64_acos() {
|
|
231
|
+
assert!((Transcendental::acos(0.5_f64) - core::f64::consts::FRAC_PI_3).abs() < 1e-15);
|
|
232
|
+
assert!((Transcendental::acos(1.0_f64)).abs() < 1e-15);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
#[test]
|
|
236
|
+
fn f64_atan() {
|
|
237
|
+
assert!((Transcendental::atan(1.0_f64) - core::f64::consts::FRAC_PI_4).abs() < 1e-15);
|
|
238
|
+
assert!((Transcendental::atan(0.0_f64)).abs() < 1e-15);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
#[test]
|
|
242
|
+
fn f64_atan2() {
|
|
243
|
+
let pi = core::f64::consts::PI;
|
|
244
|
+
// atan2(1, 1) = PI/4
|
|
245
|
+
assert!((Transcendental::atan2(1.0_f64, 1.0) - pi / 4.0).abs() < 1e-15);
|
|
246
|
+
// atan2(0, -1) = PI
|
|
247
|
+
assert!((Transcendental::atan2(0.0_f64, -1.0) - pi).abs() < 1e-15);
|
|
248
|
+
// atan2(-1, 0) = -PI/2
|
|
249
|
+
assert!((Transcendental::atan2(-1.0_f64, 0.0) + pi / 2.0).abs() < 1e-15);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#[test]
|
|
253
|
+
fn f64_sinh() {
|
|
254
|
+
assert!((Transcendental::sinh(0.0_f64)).abs() < 1e-15);
|
|
255
|
+
// sinh(1) ≈ 1.1752
|
|
256
|
+
assert!((Transcendental::sinh(1.0_f64) - 1.0_f64.sinh()).abs() < 1e-15);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
#[test]
|
|
260
|
+
fn f64_cosh() {
|
|
261
|
+
assert!((Transcendental::cosh(0.0_f64) - 1.0).abs() < 1e-15);
|
|
262
|
+
assert!((Transcendental::cosh(1.0_f64) - 1.0_f64.cosh()).abs() < 1e-15);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
#[test]
|
|
266
|
+
fn f64_tanh() {
|
|
267
|
+
assert!((Transcendental::tanh(0.0_f64)).abs() < 1e-15);
|
|
268
|
+
assert!((Transcendental::tanh(1.0_f64) - 1.0_f64.tanh()).abs() < 1e-15);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#[test]
|
|
272
|
+
fn f64_asinh() {
|
|
273
|
+
assert!((Transcendental::asinh(0.0_f64)).abs() < 1e-15);
|
|
274
|
+
assert!((Transcendental::asinh(1.0_f64) - 1.0_f64.asinh()).abs() < 1e-15);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
#[test]
|
|
278
|
+
fn f64_acosh() {
|
|
279
|
+
assert!((Transcendental::acosh(1.0_f64)).abs() < 1e-15);
|
|
280
|
+
assert!((Transcendental::acosh(2.0_f64) - 2.0_f64.acosh()).abs() < 1e-15);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#[test]
|
|
284
|
+
fn f64_atanh() {
|
|
285
|
+
assert!((Transcendental::atanh(0.0_f64)).abs() < 1e-15);
|
|
286
|
+
assert!((Transcendental::atanh(0.5_f64) - 0.5_f64.atanh()).abs() < 1e-15);
|
|
287
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#![cfg(feature = "scalar-rational")]
|
|
2
|
+
|
|
3
|
+
use num_rational::{Rational32, Rational64};
|
|
4
|
+
use qtty_core::length::Meter;
|
|
5
|
+
use qtty_core::scalar::{Exact, Scalar};
|
|
6
|
+
use qtty_core::Quantity;
|
|
7
|
+
|
|
8
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
9
|
+
// Rational64 tests
|
|
10
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
#[test]
|
|
13
|
+
fn test_rational64_scalar_basic() {
|
|
14
|
+
assert_eq!(Rational64::ZERO, Rational64::from_integer(0));
|
|
15
|
+
assert_eq!(Rational64::ONE, Rational64::from_integer(1));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#[test]
|
|
19
|
+
fn test_rational64_abs() {
|
|
20
|
+
let val = Rational64::from_integer(-5);
|
|
21
|
+
assert_eq!(Scalar::abs(val), Rational64::from_integer(5));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#[test]
|
|
25
|
+
fn test_rational64_min_max() {
|
|
26
|
+
let a = Rational64::from_integer(3);
|
|
27
|
+
let b = Rational64::from_integer(7);
|
|
28
|
+
assert_eq!(Scalar::min(a, b), Rational64::from_integer(3));
|
|
29
|
+
assert_eq!(Scalar::max(a, b), Rational64::from_integer(7));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#[test]
|
|
33
|
+
fn test_rational64_rem_euclid() {
|
|
34
|
+
let val = Rational64::from_integer(17);
|
|
35
|
+
let modulus = Rational64::from_integer(5);
|
|
36
|
+
assert_eq!(
|
|
37
|
+
Scalar::rem_euclid(val, modulus),
|
|
38
|
+
Rational64::from_integer(2)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#[test]
|
|
43
|
+
fn test_rational64_exact_conversion() {
|
|
44
|
+
let val = Rational64::new(3, 4);
|
|
45
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
46
|
+
assert_eq!(f64_val, 0.75);
|
|
47
|
+
let back: Rational64 = Exact::from_f64_approx(f64_val);
|
|
48
|
+
assert!((Exact::to_f64_approx(back) - 0.75).abs() < 0.01);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#[test]
|
|
52
|
+
fn test_rational64_quantity() {
|
|
53
|
+
let m = Quantity::<Meter, Rational64>::new(Rational64::from_integer(100));
|
|
54
|
+
assert_eq!(m.value(), Rational64::from_integer(100));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[test]
|
|
58
|
+
fn test_rational64_quantity_arithmetic() {
|
|
59
|
+
let a = Quantity::<Meter, Rational64>::new(Rational64::from_integer(10));
|
|
60
|
+
let b = Quantity::<Meter, Rational64>::new(Rational64::from_integer(5));
|
|
61
|
+
let sum = a + b;
|
|
62
|
+
assert_eq!(sum.value(), Rational64::from_integer(15));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
66
|
+
// Rational32 tests
|
|
67
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
#[test]
|
|
70
|
+
fn test_rational32_scalar_basic() {
|
|
71
|
+
assert_eq!(Rational32::ZERO, Rational32::from_integer(0));
|
|
72
|
+
assert_eq!(Rational32::ONE, Rational32::from_integer(1));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[test]
|
|
76
|
+
fn test_rational32_abs() {
|
|
77
|
+
let val = Rational32::from_integer(-5);
|
|
78
|
+
assert_eq!(Scalar::abs(val), Rational32::from_integer(5));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[test]
|
|
82
|
+
fn test_rational32_min_max() {
|
|
83
|
+
let a = Rational32::from_integer(3);
|
|
84
|
+
let b = Rational32::from_integer(7);
|
|
85
|
+
assert_eq!(Scalar::min(a, b), Rational32::from_integer(3));
|
|
86
|
+
assert_eq!(Scalar::max(a, b), Rational32::from_integer(7));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[test]
|
|
90
|
+
fn test_rational32_rem_euclid() {
|
|
91
|
+
let val = Rational32::from_integer(17);
|
|
92
|
+
let modulus = Rational32::from_integer(5);
|
|
93
|
+
assert_eq!(
|
|
94
|
+
Scalar::rem_euclid(val, modulus),
|
|
95
|
+
Rational32::from_integer(2)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#[test]
|
|
100
|
+
fn test_rational32_exact_conversion() {
|
|
101
|
+
let val = Rational32::new(1, 2);
|
|
102
|
+
let f64_val = Exact::to_f64_approx(val);
|
|
103
|
+
assert_eq!(f64_val, 0.5);
|
|
104
|
+
let back: Rational32 = Exact::from_f64_approx(f64_val);
|
|
105
|
+
assert!((Exact::to_f64_approx(back) - 0.5).abs() < 0.01);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#[test]
|
|
109
|
+
fn test_rational32_quantity() {
|
|
110
|
+
let m = Quantity::<Meter, Rational32>::new(Rational32::from_integer(100));
|
|
111
|
+
assert_eq!(m.value(), Rational32::from_integer(100));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[test]
|
|
115
|
+
fn test_rational32_quantity_arithmetic() {
|
|
116
|
+
let a = Quantity::<Meter, Rational32>::new(Rational32::from_integer(10));
|
|
117
|
+
let b = Quantity::<Meter, Rational32>::new(Rational32::from_integer(5));
|
|
118
|
+
let sum = a + b;
|
|
119
|
+
assert_eq!(sum.value(), Rational32::from_integer(15));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
123
|
+
// Negative rem_euclid (coverage for the `if r < ZERO` branch)
|
|
124
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
125
|
+
|
|
126
|
+
#[test]
|
|
127
|
+
fn test_rational64_rem_euclid_negative() {
|
|
128
|
+
// -7 rem_euclid 3 should be 2 (not -1)
|
|
129
|
+
let val = Rational64::from_integer(-7);
|
|
130
|
+
let modulus = Rational64::from_integer(3);
|
|
131
|
+
let result = Scalar::rem_euclid(val, modulus);
|
|
132
|
+
assert_eq!(result, Rational64::from_integer(2));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
#[test]
|
|
136
|
+
fn test_rational64_rem_euclid_fractional_negative() {
|
|
137
|
+
// -1/2 rem_euclid 1 should be 1/2
|
|
138
|
+
let val = Rational64::new(-1, 2);
|
|
139
|
+
let modulus = Rational64::from_integer(1);
|
|
140
|
+
let result = Scalar::rem_euclid(val, modulus);
|
|
141
|
+
assert_eq!(result, Rational64::new(1, 2));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#[test]
|
|
145
|
+
fn test_rational32_rem_euclid_negative() {
|
|
146
|
+
let val = Rational32::from_integer(-7);
|
|
147
|
+
let modulus = Rational32::from_integer(3);
|
|
148
|
+
let result = Scalar::rem_euclid(val, modulus);
|
|
149
|
+
assert_eq!(result, Rational32::from_integer(2));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#[test]
|
|
153
|
+
fn test_rational32_rem_euclid_fractional_negative() {
|
|
154
|
+
let val = Rational32::new(-1, 2);
|
|
155
|
+
let modulus = Rational32::from_integer(1);
|
|
156
|
+
let result = Scalar::rem_euclid(val, modulus);
|
|
157
|
+
assert_eq!(result, Rational32::new(1, 2));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
161
|
+
// Abs negative branch
|
|
162
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
163
|
+
|
|
164
|
+
#[test]
|
|
165
|
+
fn test_rational64_abs_positive() {
|
|
166
|
+
let val = Rational64::from_integer(5);
|
|
167
|
+
assert_eq!(Scalar::abs(val), Rational64::from_integer(5));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#[test]
|
|
171
|
+
fn test_rational32_abs_positive() {
|
|
172
|
+
let val = Rational32::from_integer(5);
|
|
173
|
+
assert_eq!(Scalar::abs(val), Rational32::from_integer(5));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
177
|
+
// Min/Max else branches
|
|
178
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
179
|
+
|
|
180
|
+
#[test]
|
|
181
|
+
fn test_rational64_min_first_smaller() {
|
|
182
|
+
let a = Rational64::from_integer(3);
|
|
183
|
+
let b = Rational64::from_integer(7);
|
|
184
|
+
assert_eq!(Scalar::min(a, b), a);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
#[test]
|
|
188
|
+
fn test_rational64_min_second_smaller() {
|
|
189
|
+
let a = Rational64::from_integer(7);
|
|
190
|
+
let b = Rational64::from_integer(3);
|
|
191
|
+
assert_eq!(Scalar::min(a, b), b);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#[test]
|
|
195
|
+
fn test_rational64_max_first_larger() {
|
|
196
|
+
let a = Rational64::from_integer(7);
|
|
197
|
+
let b = Rational64::from_integer(3);
|
|
198
|
+
assert_eq!(Scalar::max(a, b), a);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
#[test]
|
|
202
|
+
fn test_rational64_max_second_larger() {
|
|
203
|
+
let a = Rational64::from_integer(3);
|
|
204
|
+
let b = Rational64::from_integer(7);
|
|
205
|
+
assert_eq!(Scalar::max(a, b), b);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#[test]
|
|
209
|
+
fn test_rational32_min_second_smaller() {
|
|
210
|
+
let a = Rational32::from_integer(7);
|
|
211
|
+
let b = Rational32::from_integer(3);
|
|
212
|
+
assert_eq!(Scalar::min(a, b), b);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[test]
|
|
216
|
+
fn test_rational32_max_second_larger() {
|
|
217
|
+
let a = Rational32::from_integer(3);
|
|
218
|
+
let b = Rational32::from_integer(7);
|
|
219
|
+
assert_eq!(Scalar::max(a, b), b);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
223
|
+
// Commutative multiplication: Rational * Quantity
|
|
224
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
225
|
+
|
|
226
|
+
#[test]
|
|
227
|
+
fn test_rational64_commutative_mul() {
|
|
228
|
+
let q = Quantity::<Meter, Rational64>::new(Rational64::from_integer(5));
|
|
229
|
+
let result = Rational64::from_integer(3) * q;
|
|
230
|
+
assert_eq!(result.value(), Rational64::from_integer(15));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#[test]
|
|
234
|
+
fn test_rational32_commutative_mul() {
|
|
235
|
+
let q = Quantity::<Meter, Rational32>::new(Rational32::from_integer(5));
|
|
236
|
+
let result = Rational32::from_integer(3) * q;
|
|
237
|
+
assert_eq!(result.value(), Rational32::from_integer(15));
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
241
|
+
// to_lossy for rational types
|
|
242
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
243
|
+
|
|
244
|
+
#[test]
|
|
245
|
+
fn test_rational64_to_lossy() {
|
|
246
|
+
use qtty_core::length::Kilometer;
|
|
247
|
+
let km = Quantity::<Kilometer, Rational64>::new(Rational64::from_integer(2));
|
|
248
|
+
let m: Quantity<Meter, Rational64> = km.to_lossy();
|
|
249
|
+
let val_f64 = Exact::to_f64_approx(m.value());
|
|
250
|
+
assert!((val_f64 - 2000.0).abs() < 1.0);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
#[test]
|
|
254
|
+
fn test_rational32_to_lossy() {
|
|
255
|
+
use qtty_core::length::Kilometer;
|
|
256
|
+
let km = Quantity::<Kilometer, Rational32>::new(Rational32::from_integer(2));
|
|
257
|
+
let m: Quantity<Meter, Rational32> = km.to_lossy();
|
|
258
|
+
let val_f64 = Exact::to_f64_approx(m.value());
|
|
259
|
+
assert!((val_f64 - 2000.0).abs() < 1.0);
|
|
260
|
+
}
|