// HACKER NEWS — CYBERSECURITY
Faster floating point math with Rust's new API
by Itamar Turner-TrauringLast updated 02 Aug 2026, originally created 02 Aug 2026
Floating point math is often slower than integer math because the
compiler is being conservative about how it optimizes your code. While
some programming languages already had solutions of a sort, until now
Rust did not have a good stable way to deal with this limitation. But
now, starting in version 1.98, Rust will allow telling the compiler it
can optimize your code further—but with extra control so that you can
still write numeric algorithms with minimal rounding errors.
I’m going to start with an example using integers, as a baseline of what
sort of performance is possible.
To get the fastest code generation, I’m telling Rust that it’s not 2004
anymore,
and that it can generate CPU instructions that require modern hardware,
namely x86-64 machines from the past 10 years or so. Specifically, all
the code in this article is being compiled with
RUSTFLAGS="-C target-cpu=x86-64-v3". (For maximum compatibility, in
real-world usage you could provide a fallback implementation for older
computers.)
Here’s a Rust function to sum a slice of int64 numbers:
I’ll omit the code to expose this to Python, but it’s a variant of the
Rust/Python code in a previous
article.
To benchmark it, I’ll create an array of integers in NumPy:
And now I can measure the speed of summing this array:
That’s 0.5 CPU instructions per value! How does that even work?
Probably the compiler is using specialized Single Instruction, Multiple
Data (SIMD) CPU instructions, that do batch operations on multiple
values at once. The i7-12700K CPU I’m using here has 256-bit SIMD
instructions, meaning it can do some specific operations on four 64-bit
integers at a time. If there’s a specialized SIMD summing CPU
instruction, the CPU would only need to loop 250,000 times and then sum
4 integers in each iteration.