diff --git a/crates/horizon-client/src/mobs/animal_brain.rs b/crates/horizon-client/src/mobs/animal_brain.rs index 9edf2accf..cf7862773 100644 --- a/crates/horizon-client/src/mobs/animal_brain.rs +++ b/crates/horizon-client/src/mobs/animal_brain.rs @@ -742,7 +742,7 @@ impl Gate { // current order, then a stable sort. for k in &mut self.kids { let r = self.random.next_float(); - k.2 = -f64::from(r).powf(f64::from(1.0_f32 / k.1 as f32)); + k.2 = -horizon_core::jmath::pow(f64::from(r), f64::from(1.0_f32 / k.1 as f32)); } self.kids.sort_by(|a, b| a.2.total_cmp(&b.2)); for k in &mut self.kids { diff --git a/crates/horizon-client/src/mobs/monster_brain.rs b/crates/horizon-client/src/mobs/monster_brain.rs index c770858a6..bc2cfe705 100644 --- a/crates/horizon-client/src/mobs/monster_brain.rs +++ b/crates/horizon-client/src/mobs/monster_brain.rs @@ -550,7 +550,7 @@ impl RunOne { // order, then a stable sort. for k in &mut self.kids { let r = self.random.next_float(); - k.2 = -f64::from(r).powf(f64::from(1.0_f32 / k.1 as f32)); + k.2 = -horizon_core::jmath::pow(f64::from(r), f64::from(1.0_f32 / k.1 as f32)); } self.kids.sort_by(|a, b| a.2.total_cmp(&b.2)); for k in &mut self.kids { diff --git a/crates/horizon-client/src/mobs/villager_brain.rs b/crates/horizon-client/src/mobs/villager_brain.rs index 4d94ca2bb..63a112d0a 100644 --- a/crates/horizon-client/src/mobs/villager_brain.rs +++ b/crates/horizon-client/src/mobs/villager_brain.rs @@ -1101,7 +1101,7 @@ impl Gate { // current order, then a stable sort. for k in &mut self.kids { let r = self.random.next_float(); - k.2 = -f64::from(r).powf(f64::from(1.0_f32 / k.1 as f32)); + k.2 = -horizon_core::jmath::pow(f64::from(r), f64::from(1.0_f32 / k.1 as f32)); } self.kids.sort_by(|a, b| a.2.total_cmp(&b.2)); } @@ -2392,7 +2392,7 @@ impl B { } => { for k in kids.iter_mut() { let r = random.next_float(); - k.2 = -f64::from(r).powf(f64::from(1.0_f32 / k.1 as f32)); + k.2 = -horizon_core::jmath::pow(f64::from(r), f64::from(1.0_f32 / k.1 as f32)); } kids.sort_by(|a, b| a.2.total_cmp(&b.2)); for k in kids.iter_mut() { diff --git a/crates/horizon-client/src/mobs/warden.rs b/crates/horizon-client/src/mobs/warden.rs index 11394a011..44544a4f8 100644 --- a/crates/horizon-client/src/mobs/warden.rs +++ b/crates/horizon-client/src/mobs/warden.rs @@ -1061,8 +1061,8 @@ fn attack(m: &mut Mob, target: Who, cx: &mut Cx) { fn run_one(m: &mut Mob, st: &mut Warden, cx: &mut Cx) { let now = i64::from(m.age); // ShufflingList.shuffle: each entry sorts by -ln(random) / weight. - let stroll_key = -f64::from(m.random.next_float()).ln() / 2.0; - let pause_key = -f64::from(m.random.next_float()).ln(); + let stroll_key = -horizon_core::jmath::log(f64::from(m.random.next_float())) / 2.0; + let pause_key = -horizon_core::jmath::log(f64::from(m.random.next_float())); let pause_first = pause_key < stroll_key; let order = if pause_first { [false, true] diff --git a/crates/horizon-core/src/density/arithmetic.rs b/crates/horizon-core/src/density/arithmetic.rs index 296a071e8..f82b96ce2 100644 --- a/crates/horizon-core/src/density/arithmetic.rs +++ b/crates/horizon-core/src/density/arithmetic.rs @@ -8,7 +8,7 @@ pub(super) fn java_power(base: f64, exponent: f64) -> f64 { } else if exponent.is_nan() || (base.abs() == 1.0 && exponent.is_infinite()) { f64::NAN } else { - base.powf(exponent) + crate::jmath::pow(base, exponent) } } @@ -83,7 +83,7 @@ impl UnaryOp { Self::Square => value * value, Self::Cube => value * value * value, Self::Sqrt => (value as f64).sqrt() as f32, - Self::Log => (value as f64).ln() as f32, + Self::Log => crate::jmath::log(value as f64) as f32, Self::PowerBase(base) => java_power(base, value as f64) as f32, Self::PowerExponent(exponent) => java_power(value as f64, exponent) as f32, Self::Reciprocal => 1.0 / value, diff --git a/crates/horizon-core/src/density/beardifier.rs b/crates/horizon-core/src/density/beardifier.rs index 225f74714..73b94a066 100644 --- a/crates/horizon-core/src/density/beardifier.rs +++ b/crates/horizon-core/src/density/beardifier.rs @@ -208,7 +208,7 @@ fn kernel() -> &'static [f32; 13824] { let x = ((i / 24) % 24) as f64 - 12.; let y = (i % 24) as f64 - 12. + 0.5; let squared = (x * x + y * y) + z * z; - std::f64::consts::E.powf(-squared / 16.) as f32 + crate::jmath::pow(std::f64::consts::E, -squared / 16.) as f32 }) }) } diff --git a/crates/horizon-core/src/density/interval.rs b/crates/horizon-core/src/density/interval.rs index 0375dba6d..0e2652fe1 100644 --- a/crates/horizon-core/src/density/interval.rs +++ b/crates/horizon-core/src/density/interval.rs @@ -189,7 +189,7 @@ impl Interval { Ok(Self::NAI) } else { self.maximum(Self::exact(0.0)?) - .map_monotonic(|v| (v as f64).ln() as f32) + .map_monotonic(|v| crate::jmath::log(v as f64) as f32) } } pub fn power(self, exponent: Self) -> Self { diff --git a/crates/horizon-core/src/random.rs b/crates/horizon-core/src/random.rs index 89de3e1f1..609cf59be 100644 --- a/crates/horizon-core/src/random.rs +++ b/crates/horizon-core/src/random.rs @@ -300,7 +300,7 @@ pub fn marsaglia_polar(cache: &mut Option, mut next_double: impl FnMut() -> if radius >= 1.0 || radius == 0.0 { continue; } - let multiplier = (-2.0 * radius.ln() / radius).sqrt(); + let multiplier = (-2.0 * crate::jmath::log(radius) / radius).sqrt(); *cache = Some(y * multiplier); return x * multiplier; } diff --git a/crates/horizon-world/src/level/redstone.rs b/crates/horizon-world/src/level/redstone.rs index 6e4722844..92f9059e5 100644 --- a/crates/horizon-world/src/level/redstone.rs +++ b/crates/horizon-world/src/level/redstone.rs @@ -1092,7 +1092,7 @@ impl Sim<'_, L> { let pitch = if mob_head { 1.0 } else { - 2f64.powf(f64::from(note - 12) / 12.0) as f32 + horizon_core::jmath::pow(2.0, f64::from(note - 12) / 12.0) as f32 }; let sound = match instrument.as_str() { "custom_head" => "minecraft:ui.button.click".to_owned(), diff --git a/crates/horizon-world/src/level/sculk.rs b/crates/horizon-world/src/level/sculk.rs index a831f2151..46073cf5e 100644 --- a/crates/horizon-world/src/level/sculk.rs +++ b/crates/horizon-world/src/level/sculk.rs @@ -315,7 +315,8 @@ impl Sim<'_, L> { if charge > 0 && let Some(faces) = faces { - let particles = ((f64::from(charge) + 1.0).ln() as f32 / 2.3) as i32 + 1; + let particles = + (horizon_core::jmath::log(f64::from(charge) + 1.0) as f32 / 2.3) as i32 + 1; let data = (particles << 6) + pack_faces(&faces); self.level_event(3006, pos, data); } diff --git a/crates/horizon-world/src/worldgen/dripstone.rs b/crates/horizon-world/src/worldgen/dripstone.rs index 2358bd723..8b67e0eca 100644 --- a/crates/horizon-world/src/worldgen/dripstone.rs +++ b/crates/horizon-world/src/worldgen/dripstone.rs @@ -545,9 +545,9 @@ fn speleothem_height(distance: f64, radius: f64, scale: f64, bluntness: f64) -> distance }; let r = distance / radius * 0.384; - let part1 = 0.75 * r.powf(1.3333333333333333); - let part2 = r.powf(0.6666666666666666); - let part3 = 0.3333333333333333 * r.ln(); + let part1 = 0.75 * horizon_core::jmath::pow(r, 1.3333333333333333); + let part2 = horizon_core::jmath::pow(r, 0.6666666666666666); + let part3 = 0.3333333333333333 * horizon_core::jmath::log(r); let height = (scale * (part1 - part2 - part3)).max(0.0); height / 0.384 * radius } diff --git a/crates/horizon-world/src/worldgen/end_spike.rs b/crates/horizon-world/src/worldgen/end_spike.rs index a2c00ee08..e76982853 100644 --- a/crates/horizon-world/src/worldgen/end_spike.rs +++ b/crates/horizon-world/src/worldgen/end_spike.rs @@ -38,8 +38,8 @@ pub fn spikes_for_seed(seed: i64) -> Vec { 2.0 * (-std::f64::consts::PI + (std::f64::consts::PI / 10.0) * f64::from(i)); let size = sizes[i as usize]; EndSpike { - center_x: (42.0 * angle.cos()).floor() as i32, - center_z: (42.0 * angle.sin()).floor() as i32, + center_x: (42.0 * horizon_core::jmath::cos(angle)).floor() as i32, + center_z: (42.0 * horizon_core::jmath::sin(angle)).floor() as i32, radius: 2 + size / 3, height: 76 + size * 3, guarded: size == 1 || size == 2, diff --git a/crates/horizon-world/src/worldgen/iceberg.rs b/crates/horizon-world/src/worldgen/iceberg.rs index 2bfeff29a..3a7409ad3 100644 --- a/crates/horizon-world/src/worldgen/iceberg.rs +++ b/crates/horizon-world/src/worldgen/iceberg.rs @@ -29,7 +29,7 @@ fn ceil(v: f32) -> i32 { f64::from(v).ceil() as i32 } fn pow2(v: i32) -> f64 { - f64::from(v).powf(2.0) + horizon_core::jmath::pow(f64::from(v), 2.0) } impl IcebergFeature { pub(crate) fn decode( @@ -380,7 +380,11 @@ impl IcebergFeature { fn signed_ellipse(xo: i32, zo: i32, origin: [i32; 3], a: i32, c: i32, angle: f64) -> f64 { let dx = f64::from(xo - origin[0]); let dz = f64::from(zo - origin[2]); - ((dx * angle.cos() - dz * angle.sin()) / f64::from(a)).powf(2.0) - + ((dx * angle.sin() + dz * angle.cos()) / f64::from(c)).powf(2.0) + let (sin, cos) = ( + horizon_core::jmath::sin(angle), + horizon_core::jmath::cos(angle), + ); + horizon_core::jmath::pow((dx * cos - dz * sin) / f64::from(a), 2.0) + + horizon_core::jmath::pow((dx * sin + dz * cos) / f64::from(c), 2.0) - 1.0 } diff --git a/crates/horizon-world/src/worldgen/ore_feature.rs b/crates/horizon-world/src/worldgen/ore_feature.rs index c4cbe447e..9d723ae40 100644 --- a/crates/horizon-world/src/worldgen/ore_feature.rs +++ b/crates/horizon-world/src/worldgen/ore_feature.rs @@ -155,7 +155,10 @@ impl OreFeature { let spread_xy = self.size as f32 / 8.0; let max_radius = ((self.size as f32 / 16.0 * 2.0 + 1.0) / 2.0).ceil() as i32; let (ox, oz) = (f64::from(origin[0]), f64::from(origin[2])); - let (sin, cos) = (f64::from(dir).sin(), f64::from(dir).cos()); + let (sin, cos) = ( + horizon_core::jmath::sin(f64::from(dir)), + horizon_core::jmath::cos(f64::from(dir)), + ); let spread = f64::from(spread_xy); let x0 = ox + sin * spread; let x1 = ox - sin * spread; diff --git a/crates/horizon-world/src/worldgen/structure/stronghold.rs b/crates/horizon-world/src/worldgen/structure/stronghold.rs index 95fcd679c..eb31e0627 100644 --- a/crates/horizon-world/src/worldgen/structure/stronghold.rs +++ b/crates/horizon-world/src/worldgen/structure/stronghold.rs @@ -30,7 +30,10 @@ pub fn ring_positions( let dist = f64::from(4 * distance + distance * circle * 6) + (random.next_double() - 0.5) * (f64::from(distance) * 2.5); let round = |v: f64| (v + 0.5).floor() as i64 as i32; - let (x, z) = (round(angle.cos() * dist), round(angle.sin() * dist)); + let (x, z) = ( + round(horizon_core::jmath::cos(angle) * dist), + round(horizon_core::jmath::sin(angle) * dist), + ); let mut search = random.fork(); let (cx, cz) = ((x * 16 + 8) >> 2, (z * 16 + 8) >> 2); let mut found = 0; diff --git a/crates/horizon-world/src/worldgen/tree/trunk.rs b/crates/horizon-world/src/worldgen/tree/trunk.rs index b88e88bfc..741f0e2a7 100644 --- a/crates/horizon-world/src/worldgen/tree/trunk.rs +++ b/crates/horizon-world/src/worldgen/tree/trunk.rs @@ -690,8 +690,9 @@ impl TrunkPlacer { let height = tree_height + 2; let trunk_height = (f64::from(height) * 0.618).floor() as i32; Self::place_below_trunk(run, tree, tb::offset(origin, 0, -1, 0))?; - let clusters_per_y = - 1.min((1.382 + (1.0 * f64::from(height) / 13.0).powf(2.0)).floor() as i32); + let clusters_per_y = 1.min( + (1.382 + horizon_core::jmath::pow(1.0 * f64::from(height) / 13.0, 2.0)).floor() as i32, + ); let trunk_top = origin[1].wrapping_add(trunk_height); let mut relative_y = height - 5; // (attachment position, branch base y) @@ -704,8 +705,8 @@ impl TrunkPlacer { let radius = 1.0 * f64::from(shape) * (f64::from(run.random.next_float()) + 0.328); let angle = f64::from(run.random.next_float() * 2.0f32) * std::f64::consts::PI; - let x = radius * angle.sin() + 0.5; - let z = radius * angle.cos() + 0.5; + let x = radius * horizon_core::jmath::sin(angle) + 0.5; + let z = radius * horizon_core::jmath::cos(angle) + 0.5; let check_start = tb::offset(origin, x.floor() as i32, relative_y - 1, z.floor() as i32); let check_end = tb::offset(check_start, 0, 5, 0); diff --git a/tools/parity_hosts.json b/tools/parity_hosts.json index 5347c9257..4d5bd1bcd 100644 --- a/tools/parity_hosts.json +++ b/tools/parity_hosts.json @@ -9,12 +9,7 @@ "python": "/opt/homebrew/bin/python3.13", "rsync": "/opt/homebrew/bin/rsync", "jobs": 14, - "exclude": { - "options": "Rust's f64::powf uses the platform libm, which rounds differently on macOS", - "chunk_generation": "one ocean ruined portal differs on macOS (platform float math)", - "world_border_render": "the wall's alpha differs by one ulp on macOS (platform float math)", - "mob_ai": "mob movement differs on macOS (platform float math in random positions)" - } + "exclude": {} }, "thinkpad": { "ssh": "thinkpad",