diff --git a/e2e-tests/float_tests/src/lib.rs b/e2e-tests/float_tests/src/lib.rs index e0f17155..bd773ca3 100644 --- a/e2e-tests/float_tests/src/lib.rs +++ b/e2e-tests/float_tests/src/lib.rs @@ -10,7 +10,7 @@ use xrpl_common_stdlib::fields::locator::Locator; use xrpl_common_stdlib::host::trace::{trace, trace_float, trace_hex, trace_num}; use xrpl_common_stdlib::host::{ RoundingMode, cache_le, float_add, float_cmp, float_div, float_from_int, float_from_mant_exp, - float_from_uint, float_mult, float_pow, float_root, float_sub, le_arr_len, le_field, le_inner, + float_from_uint, float_mult, float_pow, float_sub, le_arr_len, le_field, le_inner, }; use xrpl_common_stdlib::sfield; use xrpl_common_stdlib::types::iou_number::{FLOAT_NEGATIVE_ONE, FLOAT_ONE}; @@ -316,68 +316,6 @@ fn test_float_pow() { ); } -fn test_float_root() { - trace("\n$$$ test_float_root $$$"); - - let mut f9: [u8; 8] = [0u8; 8]; - unsafe { float_from_int(9, f9.as_mut_ptr(), 8, RoundingMode::ToNearest.into()) }; - let mut f_compute: [u8; 8] = [0u8; 8]; - unsafe { - float_root( - f9.as_ptr(), - 8, - 2, - f_compute.as_mut_ptr(), - 8, - RoundingMode::ToNearest.into(), - ) - }; - trace_float(" float sqrt of 9:", &f_compute); - unsafe { - float_root( - f9.as_ptr(), - 8, - 3, - f_compute.as_mut_ptr(), - 8, - RoundingMode::ToNearest.into(), - ) - }; - trace_float(" float cbrt of 9:", &f_compute); - - let mut f1000000: [u8; 8] = [0u8; 8]; - unsafe { - float_from_int( - 1000000, - f1000000.as_mut_ptr(), - 8, - RoundingMode::ToNearest.into(), - ) - }; - unsafe { - float_root( - f1000000.as_ptr(), - 8, - 3, - f_compute.as_mut_ptr(), - 8, - RoundingMode::ToNearest.into(), - ) - }; - trace_float(" float cbrt of 1000000:", &f_compute); - unsafe { - float_root( - f1000000.as_ptr(), - 8, - 6, - f_compute.as_mut_ptr(), - 8, - RoundingMode::ToNearest.into(), - ) - }; - trace_float(" float 6th root of 1000000:", &f_compute); -} - fn test_float_negate() { trace("\n$$$ test_float_negate $$$"); @@ -466,7 +404,6 @@ pub extern "C" fn escrow_finish() -> i32 { test_float_add_subtract(); test_float_mult_divide(); test_float_pow(); - test_float_root(); test_float_negate(); test_float_invert(); diff --git a/xrpl-common-stdlib/src/host/host_bindings_empty.rs b/xrpl-common-stdlib/src/host/host_bindings_empty.rs index 9f321b6b..dd3d4ffa 100644 --- a/xrpl-common-stdlib/src/host/host_bindings_empty.rs +++ b/xrpl-common-stdlib/src/host/host_bindings_empty.rs @@ -155,7 +155,6 @@ export_host_functions! { fn float_mult(_in_buff1: *const u8, _in_buff1_len: usize, _in_buff2: *const u8, _in_buff2_len: usize, _out_buff: *mut u8, _out_buff_len: usize, _rounding_mode: i32) -> i32; fn float_div(_in_buff1: *const u8, _in_buff1_len: usize, _in_buff2: *const u8, _in_buff2_len: usize, _out_buff: *mut u8, _out_buff_len: usize, _rounding_mode: i32) -> i32; fn float_pow(_in_buff: *const u8, _in_buff_len: usize, _pow: i32, _out_buff: *mut u8, _out_buff_len: usize, _rounding_mode: i32) -> i32; - fn float_root(_in_buff: *const u8, _in_buff_len: usize, _root: i32, _out_buff: *mut u8, _out_buff_len: usize, _rounding_mode: i32) -> i32; } diff --git a/xrpl-common-stdlib/src/host/host_bindings_test.rs b/xrpl-common-stdlib/src/host/host_bindings_test.rs index 2ec76e3b..94898e6c 100644 --- a/xrpl-common-stdlib/src/host/host_bindings_test.rs +++ b/xrpl-common-stdlib/src/host/host_bindings_test.rs @@ -186,8 +186,6 @@ pub fn apply_default_expectations(mock: &mut MockHostBindings) { .returning(|_, _, _, _, _, out_buff_len, _| out_buff_len as i32); mock.expect_float_pow() .returning(|_, _, _, _, out_buff_len, _| out_buff_len as i32); - mock.expect_float_root() - .returning(|_, _, _, _, out_buff_len, _| out_buff_len as i32); // Trace mock.expect_trace().returning(|_, _, _, _, _| ()); @@ -313,7 +311,6 @@ export_host_functions! { fn float_mult(in_buff1: *const u8, in_buff1_len: usize, in_buff2: *const u8, in_buff2_len: usize, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; fn float_div(in_buff1: *const u8, in_buff1_len: usize, in_buff2: *const u8, in_buff2_len: usize, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; fn float_pow(in_buff: *const u8, in_buff_len: usize, pow: i32, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; - fn float_root(in_buff: *const u8, in_buff_len: usize, root: i32, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; // Host Function Category: TRACE fn trace(msg_read_ptr: *const u8, msg_read_len: usize, data_type: i32, data_read_ptr: *const u8, data_read_len: usize) -> (); diff --git a/xrpl-common-stdlib/src/host/host_bindings_trait.rs b/xrpl-common-stdlib/src/host/host_bindings_trait.rs index bde1c16a..464078e3 100644 --- a/xrpl-common-stdlib/src/host/host_bindings_trait.rs +++ b/xrpl-common-stdlib/src/host/host_bindings_trait.rs @@ -1478,29 +1478,6 @@ pub trait HostBindings { rounding_mode: i32, ) -> i32; - /// Calculates the nth root of an opaque float value - /// # Parameters - /// * `in_buff` - Pointer to input float value - /// * `in_buff_len` - The length of the input float value in bytes - /// * `root` - The root to calculate (e.g., 2 for square root) - /// * `out_buff` - Pointer to output buffer where result will be written - /// * `out_buff_len` - The length of the output buffer in bytes - /// * `rounding_mode` - Rounding mode to use for the operation - /// # Returns - /// 8 on success, error code otherwise - /// - /// # Safety - /// Caller must ensure all pointer parameters point to valid memory - unsafe fn float_root( - &self, - in_buff: *const u8, - in_buff_len: usize, - root: i32, - out_buff: *mut u8, - out_buff_len: usize, - rounding_mode: i32, - ) -> i32; - // ############################# // Host Function Category: TRACE // ############################# diff --git a/xrpl-common-stdlib/src/host/host_bindings_wasm.rs b/xrpl-common-stdlib/src/host/host_bindings_wasm.rs index 27439dc0..fe488287 100644 --- a/xrpl-common-stdlib/src/host/host_bindings_wasm.rs +++ b/xrpl-common-stdlib/src/host/host_bindings_wasm.rs @@ -349,14 +349,6 @@ mod host_defined_functions { out_buff_len: usize, rounding_mode: i32, ) -> i32; - pub(super) fn float_root( - in_buff: *const u8, - in_buff_len: usize, - root: i32, - out_buff: *mut u8, - out_buff_len: usize, - rounding_mode: i32, - ) -> i32; pub(super) fn trace( msg_read_ptr: *const u8, msg_read_len: usize, @@ -1233,27 +1225,6 @@ impl HostBindings for WasmHostBindings { } } - unsafe fn float_root( - &self, - in_buff: *const u8, - in_buff_len: usize, - root: i32, - out_buff: *mut u8, - out_buff_len: usize, - rounding_mode: i32, - ) -> i32 { - unsafe { - host_defined_functions::float_root( - in_buff, - in_buff_len, - root, - out_buff, - out_buff_len, - rounding_mode, - ) - } - } - unsafe fn trace( &self, msg_read_ptr: *const u8, @@ -1362,7 +1333,6 @@ export_host_functions! { fn float_mult(in_buff1: *const u8, in_buff1_len: usize, in_buff2: *const u8, in_buff2_len: usize, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; fn float_div(in_buff1: *const u8, in_buff1_len: usize, in_buff2: *const u8, in_buff2_len: usize, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; fn float_pow(in_buff: *const u8, in_buff_len: usize, pow: i32, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; - fn float_root(in_buff: *const u8, in_buff_len: usize, root: i32, out_buff: *mut u8, out_buff_len: usize, rounding_mode: i32) -> i32; // Host Function Category: TRACE fn trace(msg_read_ptr: *const u8, msg_read_len: usize, data_type: i32, data_read_ptr: *const u8, data_read_len: usize) -> (); diff --git a/xrpl-common-stdlib/src/host/mod.rs b/xrpl-common-stdlib/src/host/mod.rs index 0d054369..7f4c6205 100644 --- a/xrpl-common-stdlib/src/host/mod.rs +++ b/xrpl-common-stdlib/src/host/mod.rs @@ -13,7 +13,7 @@ //! - `float_from_stamount` / `float_from_stnumber` - Convert XRP ledger types to float format //! - `float_to_int` / `float_to_mant_exp` - Convert float to integer or decomposed form //! - `float_add` / `float_sub` / `float_mult` / `float_div` - Arithmetic -//! - `float_pow` / `float_root` - Mathematical functions +//! - `float_pow` - Mathematical functions //! - `float_cmp` - Comparison operations //! //! All operations support explicit rounding modes; see [`RoundingMode`]. diff --git a/xrpl-common-stdlib/src/types/number.rs b/xrpl-common-stdlib/src/types/number.rs index 8768362a..3f0b1198 100644 --- a/xrpl-common-stdlib/src/types/number.rs +++ b/xrpl-common-stdlib/src/types/number.rs @@ -257,22 +257,6 @@ impl Number { }; match_result_code_with_expected_bytes(rescode, NUMBER_SIZE, || Number(out)) } - - /// Returns the `n`th root of `self` (e.g. `n = 2` for the square root), rounding per `rounding`. - pub fn root(&self, n: i32, rounding: RoundingMode) -> Result { - let mut out = [0u8; NUMBER_SIZE]; - let rescode = unsafe { - host::float_root( - self.0.as_ptr(), - self.0.len(), - n, - out.as_mut_ptr(), - NUMBER_SIZE, - rounding.into(), - ) - }; - match_result_code_with_expected_bytes(rescode, NUMBER_SIZE, || Number(out)) - } } impl From<[u8; NUMBER_SIZE]> for Number { @@ -642,21 +626,4 @@ mod tests { fn test_empty_buffer_is_number_sized() { assert_eq!(::empty_buffer(), [0u8; NUMBER_SIZE]); } - - #[test] - fn test_float_root_success() { - let mut mock = MockHostBindings::new(); - mock.expect_float_root() - .times(1) - .returning(|_, _, _, out, out_len, _| { - unsafe { out.copy_from_nonoverlapping(SAMPLE.as_ptr(), NUMBER_SIZE) } - out_len as i32 - }); - let _guard = setup_mock(mock); - - assert_eq!( - Number(SAMPLE).root(2, RoundingMode::ToNearest).unwrap(), - Number(SAMPLE) - ); - } }