Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 1 addition & 64 deletions e2e-tests/float_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 $$$");

Expand Down Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion xrpl-common-stdlib/src/host/host_bindings_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

Expand Down
3 changes: 0 additions & 3 deletions xrpl-common-stdlib/src/host/host_bindings_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_, _, _, _, _| ());
Expand Down Expand Up @@ -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) -> ();
Expand Down
23 changes: 0 additions & 23 deletions xrpl-common-stdlib/src/host/host_bindings_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// #############################
Expand Down
30 changes: 0 additions & 30 deletions xrpl-common-stdlib/src/host/host_bindings_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) -> ();
Expand Down
2 changes: 1 addition & 1 deletion xrpl-common-stdlib/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down
33 changes: 0 additions & 33 deletions xrpl-common-stdlib/src/types/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Number> {
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 {
Expand Down Expand Up @@ -642,21 +626,4 @@ mod tests {
fn test_empty_buffer_is_number_sized() {
assert_eq!(<Number as FieldDecoder>::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)
);
}
}
Loading