heh
-rw-r--r--src/main.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index c8a48f6..6b55083 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,7 @@
#![allow(
confusable_idents,
uncommon_codepoints,
+ internal_features,
mixed_script_confusables,
incomplete_features
)]
@@ -19,15 +20,17 @@
slice_as_chunks,
array_chunks,
slice_split_once,
+ core_intrinsics,
byte_slice_trim_ascii
)]
extern crate test;
+use core::intrinsics::{fadd_fast as af, fdiv_fast as df, fmul_fast as mf, fsub_fast as sf};
pub mod util;
-use std::{io::BufRead, mem::MaybeUninit};
+use std::mem::MaybeUninit;
pub use util::prelude::*;
-pub fn intersect(
+pub unsafe fn intersect(
p0x: f64,
p0y: f64,
v0x: f64,
@@ -37,10 +40,16 @@ pub fn intersect(
v1x: f64,
v1y: f64,
) -> Option<(f64, f64)> {
- let x = ((p1y - p0y) + p0x * (v0y / v0x) - p1x * (v1y / v1x)) / ((v0y / v0x) - (v1y / v1x));
- let t0 = (x - p0x) / v0x;
- let t1 = (x - p1x) / v1x;
- (t0 > 0. && t1 > 0.).then_some((x, p0y + t0 * v0y))
+ let x = df(
+ sf(
+ af(sf(p1y, p0y), mf(p0x, df(v0y, v0x))),
+ mf(p1x, df(v1y, v1x)),
+ ),
+ sf(df(v0y, v0x), df(v1y, v1x)),
+ );
+ let t0 = df(sf(x, p0x), v0x);
+ let t1 = df(sf(x, p1x), v1x);
+ (t0 > 0. && t1 > 0.).then_some((x, af(p0y, mf(t0, v0y))))
}
pub fn run(i: &str) -> impl Display {
@@ -53,6 +62,7 @@ pub fn run(i: &str) -> impl Display {
x.skip(1);
let β = 読む::迄::<i64>(&mut x, b',') as f64;
x.skip(2);
+ // memchr bad here
while x.by().ψ() != b' ' {}
x.skip(2);
let δ = 読む::負迄(&mut x, b',') as f64;
@@ -68,7 +78,7 @@ pub fn run(i: &str) -> impl Display {
let mut sum = 0;
for (i, &([x0, y0], [v0x, v0y])) in v.iter().enumerate() {
for &([x1, y1], [v1x, v1y]) in &v[i..] {
- if let Some((x, y)) = intersect(x0, y0, v0x, v0y, x1, y1, v1x, v1y) {
+ if let Some((x, y)) = unsafe { intersect(x0, y0, v0x, v0y, x1, y1, v1x, v1y) } {
let min = 200000000000000.;
let max = 400000000000000.;
if x > min && x < max && y > min && y < max {