Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#[inline(never)]
fn stylo(intpart: &[u32], fracpart: &[u32]) -> f32 {
let mut integral = 0.0f64;
let mut fractional = 0.0f64;
let mut factor = 0.1;
for i in intpart {
integral = integral * 10. + *i as f64;
}
for i in fracpart {
fractional += *i as f64 * factor;
factor *= 0.1;
}
1. *(integral + fractional) as f32 / 100.
}
#[inline(never)]
fn gecko(intpart: &[u32], fracpart: &[u32]) -> f32 {
let mut integral = 0;
let mut fractional = 0.0f64;
let mut divisor = 10.;
for i in intpart {
integral = integral * 10 + *i;
}
for i in fracpart {
fractional += *i as f64 / divisor;
divisor *= 10.;
}
(((integral as f64) + fractional) / 100.) as f32
}
fn main(){
let intpart = [4, 7];
let fracpart = [9, 9, 5];
println!("{:.10} {:.10}", stylo(&intpart, &fracpart) * 100., gecko(&intpart, &fracpart) * 100.);
println!("{:.10} {:.10}", 47.995f64 as f32 / 100., (47.995f64 / 100.) as f32);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment