Use y_from_x naming for functions
This commit is contained in:
@@ -30,7 +30,7 @@ pub unsafe fn reset_a_and_c() {
|
||||
/// Takes a pointer argument due to the inappropriate C function
|
||||
/// signatures generated from Rust's sized arrays, see
|
||||
/// https://github.com/eqrion/cbindgen/issues/171
|
||||
pub unsafe fn ushort_arr3_to_uint48(arr_ptr: *const c_ushort) -> u64 {
|
||||
pub unsafe fn uint48_from_ushort_arr3(arr_ptr: *const c_ushort) -> u64 {
|
||||
let arr = [*arr_ptr.offset(0), *arr_ptr.offset(1), *arr_ptr.offset(2)];
|
||||
|
||||
/* Cast via u16 to ensure we get only the lower 16 bits of each
|
||||
@@ -51,7 +51,7 @@ pub unsafe fn set_ushort_arr3_from_uint48(arr_ptr: *mut c_ushort, value: u64) {
|
||||
/// Modifies the passed argument in-place and returns the new value as a
|
||||
/// u64. The input argument must be a size-3 array.
|
||||
pub unsafe fn generator_step(xi_arr_ptr: *mut c_ushort) -> u64 {
|
||||
let old_xi: u64 = ushort_arr3_to_uint48(xi_arr_ptr);
|
||||
let old_xi: u64 = uint48_from_ushort_arr3(xi_arr_ptr);
|
||||
|
||||
/* The recurrence relation of the linear congruential generator,
|
||||
* X_(n+1) = (a * X_n + c) % m,
|
||||
@@ -65,7 +65,7 @@ pub unsafe fn generator_step(xi_arr_ptr: *mut c_ushort) -> u64 {
|
||||
|
||||
/// Get a C `double` from a 48-bit integer (for `drand48()` and
|
||||
/// `erand48()`).
|
||||
pub fn x_to_float64(x: u64) -> c_double {
|
||||
pub fn float64_from_x(x: u64) -> c_double {
|
||||
/* We set the exponent to 0, and the 48-bit integer is copied into the high
|
||||
* 48 of the 52 significand bits. The value then lies in the range
|
||||
* [1.0, 2.0), from which we simply subtract 1.0. */
|
||||
@@ -74,13 +74,13 @@ pub fn x_to_float64(x: u64) -> c_double {
|
||||
|
||||
/// Get the high 31 bits of a 48-bit integer (for `lrand48()` and
|
||||
/// `nrand48()`).
|
||||
pub fn x_to_uint31(x: u64) -> c_long {
|
||||
pub fn uint31_from_x(x: u64) -> c_long {
|
||||
(x >> 17) as c_long
|
||||
}
|
||||
|
||||
/// Get the high 32 bits, signed, of a 48-bit integer (for `mrand48()`
|
||||
/// and `jrand48()`).
|
||||
pub fn x_to_int32(x: u64) -> c_long {
|
||||
pub fn int32_from_x(x: u64) -> c_long {
|
||||
// Cast via i32 to ensure we get the sign correct
|
||||
c_long::from((x >> 16) as i32)
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn drand48() -> c_double {
|
||||
let new_xi = lcg48::generator_step(lcg48::DEFAULT_XI.as_mut_ptr());
|
||||
lcg48::x_to_float64(new_xi)
|
||||
lcg48::float64_from_x(new_xi)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -249,7 +249,7 @@ pub extern "C" fn ecvt(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn erand48(xsubi: *mut c_ushort) -> c_double {
|
||||
let new_xi = lcg48::generator_step(xsubi);
|
||||
lcg48::x_to_float64(new_xi)
|
||||
lcg48::float64_from_x(new_xi)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -365,7 +365,7 @@ pub extern "C" fn initstate(seec: c_uint, state: *mut c_char, size: size_t) -> *
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn jrand48(xsubi: *mut c_ushort) -> c_long {
|
||||
let new_xi = lcg48::generator_step(xsubi);
|
||||
lcg48::x_to_int32(new_xi)
|
||||
lcg48::int32_from_x(new_xi)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -384,9 +384,9 @@ pub unsafe extern "C" fn lcong48(param: *mut c_ushort) {
|
||||
|
||||
/* Go through this ptr -> u64 -> ptr conversion to ensure we only
|
||||
* get the lower 16 bits of each element. */
|
||||
let new_xi = lcg48::ushort_arr3_to_uint48(param.offset(0));
|
||||
let new_xi = lcg48::uint48_from_ushort_arr3(param.offset(0));
|
||||
lcg48::set_ushort_arr3_from_uint48(lcg48::DEFAULT_XI.as_mut_ptr(), new_xi);
|
||||
lcg48::A = lcg48::ushort_arr3_to_uint48(param.offset(3));
|
||||
lcg48::A = lcg48::uint48_from_ushort_arr3(param.offset(3));
|
||||
lcg48::C = *param.offset(6) as u16; // c_ushort may be more than 16 bits
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ pub extern "C" fn lldiv(numer: c_longlong, denom: c_longlong) -> lldiv_t {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn lrand48() -> c_long {
|
||||
let new_xi = lcg48::generator_step(lcg48::DEFAULT_XI.as_mut_ptr());
|
||||
lcg48::x_to_uint31(new_xi)
|
||||
lcg48::uint31_from_x(new_xi)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -583,13 +583,13 @@ pub extern "C" fn mkstemps(name: *mut c_char, suffix_len: c_int) -> c_int {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn mrand48() -> c_long {
|
||||
let new_xi = lcg48::generator_step(lcg48::DEFAULT_XI.as_mut_ptr());
|
||||
lcg48::x_to_int32(new_xi)
|
||||
lcg48::int32_from_x(new_xi)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn nrand48(xsubi: *mut c_ushort) -> c_long {
|
||||
let new_xi = lcg48::generator_step(xsubi);
|
||||
lcg48::x_to_uint31(new_xi)
|
||||
lcg48::uint31_from_x(new_xi)
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
@@ -710,7 +710,7 @@ pub unsafe extern "C" fn seed48(seed16v: *mut c_ushort) -> *mut c_ushort {
|
||||
|
||||
lcg48::STASHED_XI = lcg48::DEFAULT_XI;
|
||||
|
||||
let new_xi = lcg48::ushort_arr3_to_uint48(seed16v);
|
||||
let new_xi = lcg48::uint48_from_ushort_arr3(seed16v);
|
||||
lcg48::set_ushort_arr3_from_uint48(lcg48::DEFAULT_XI.as_mut_ptr(), new_xi);
|
||||
|
||||
lcg48::STASHED_XI.as_mut_ptr()
|
||||
|
||||
Reference in New Issue
Block a user