From 60b3807ab325bee3252bc0c451f0dcd5c4633ab7 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Tue, 8 Mar 2022 23:21:58 +0800 Subject: [PATCH] nac3standalone: add test for abs function --- nac3standalone/demo/demo.rs | 4 +++- nac3standalone/demo/src/min_max_abs.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/nac3standalone/demo/demo.rs b/nac3standalone/demo/demo.rs index 2a00eabd..7f42c89b 100644 --- a/nac3standalone/demo/demo.rs +++ b/nac3standalone/demo/demo.rs @@ -40,7 +40,9 @@ pub extern "C" fn output_uint64(x: u64) { #[no_mangle] pub extern "C" fn output_float64(x: f64) { - println!("{}", x); + // debug output to preserve the digits after the decimal points + // to match python `print` function + println!("{:?}", x); } #[no_mangle] diff --git a/nac3standalone/demo/src/min_max_abs.py b/nac3standalone/demo/src/min_max_abs.py index 81dbb3f6..15153fd5 100644 --- a/nac3standalone/demo/src/min_max_abs.py +++ b/nac3standalone/demo/src/min_max_abs.py @@ -65,4 +65,27 @@ def run() -> int32: output_float64(max(-12.234, 3.23)) output_float64(max(0.1, 12.3)) output_float64(max(1.1, 1.1)) + + # abs =========== + output_int32(int32(abs(False))) + output_int32(int32(abs(True))) + + output_int32(abs(0)) + output_int32(abs(-3)) + output_int32(abs(2)) + + output_int64(abs(int64(-12))) + output_int64(abs(int64(0))) + output_int64(abs(int64(2))) + + output_uint32(abs(uint32(0))) + output_uint32(abs(uint32(24))) + + output_uint64(abs(uint64(0))) + output_uint64(abs(uint64(24))) + + output_float64(abs(-12.234)) + output_float64(abs(-0.0)) + output_float64(abs(1.1)) + return 0