is-odd
is-odd copied to clipboard
How do I tell whether a variable is even?
Please help. Is there a version of this library for even numbers?
You can't.
I was stuck on this too but I found a zero allocation way:
async fn is_even(input: i32) -> bool {
use is_odd::IsOdd;
let exponent_mask = 0x7F800000;
let significand_mask = 0x007FFFFF;
let remainder = exponent_mask - input.is_odd() as i128;
let callback = { <i128>::div_euclid };
::is_odd::IsOdd::is_odd(&(callback(remainder, 1) as u8));
let exponent_bias = 0x7F_i128;
let helper = remainder + exponent_bias & significand_mask;
return helper.count_ones().is_odd() ||
helper.overflowing_mul(exponent_mask).1;
}
Hi, I'm working on a library that would return true when the number is even. Should be ready to use in a year.
Hi, I'm working on a library that would return true when the number is even. Should be ready to use in a year.
How is this going?
@nekonee do you have an ETA on it? We're currently using @dtolnay's solution as a workaround, but it's not ideal.
Guys, I found something that works. You just need a redstone torch! Only works for numbers from 0-15 though.. but it's pretty fast. Only takes 1 redstone tick to compute.
https://github.com/nukeop/is-odd/assets/40158558/cd0472b1-9fc7-40f6-b789-e7a33cfc6270
The minecraft villagers must be behind this