From 9a2db04a8f9b3ca29add278909adf239d78f6ff4 Mon Sep 17 00:00:00 2001 From: raphaelDkhn <113879115+raphaelDkhn@users.noreply.github.com> Date: Tue, 8 Oct 2024 17:56:51 +0300 Subject: [PATCH] fix abs --- packages/numbers/src/f64/ops.cairo | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/numbers/src/f64/ops.cairo b/packages/numbers/src/f64/ops.cairo index 1ec747ef0..1c4817d63 100644 --- a/packages/numbers/src/f64/ops.cairo +++ b/packages/numbers/src/f64/ops.cairo @@ -8,8 +8,8 @@ pub(crate) fn abs(a: F64) -> F64 { return F64 { d: NaN }; } - if a.d <= 0 { - F64 { d: a.d * ONE } + if a.d < 0 { + F64 { d: -a.d } } else { a } @@ -418,6 +418,14 @@ mod tests { assert(exp2(a).d == 72057594037927936, 'invalid exp2 of 2'); } + #[test] + #[available_gas(400000)] + fn test_exp2_neg() { + let a: F64 = FixedTrait::new(-925062941); + println!("A: {:}", exp2(a).d); + assert(exp2(a).d == -6835341966, 'invalid exp2 of 2'); + } + #[test] #[available_gas(20000)] fn test_exp2_int() {