frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Comparing floating-point numbers (2012)

https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
26•sph•11mo ago

Comments

LegionMammal978•11mo ago
I'd argue that any equality comparison of floating-point numbers is asking for trouble, unless you're specifically working with small dyadic fractions (using exact comparison) or testing a purely heuristic 'closeness' condition (using fuzzy comparison).

Of course, inequalities show up in a lot more places, but are similarly fraught with difficulty, since mathematical statements may fail to translate to floating-point inequalities. E.g., in computational geometry, people have written entire papers about optimizing correct orientation predicates [0], since the naive method can easily break at small angles. This sort of thing is what often shows up as tiny seams in 3D video-game geometry.

[0] https://www.cs.cmu.edu/~quake/robust.html

mtklein•11mo ago
My preferred way to compare floats as being interchangeably equivalent in unit tests is

    bool equiv(float x, float y) {
        return (x <= y && y <= x)
            || (x != x && y != y);
    }
This handles things like ±0 and NaNs (while NaNs can't be IEEE-754-equal per se, they're almost always interchangeable), and convinces -Wfloat-equal you kinda know what you're doing. Also everything visually lines up real neat and tidy, which I find makes it easy to remember.

Outside unit tests... I haven't really encountered many places where float equality is actually what I want to test. It's usually some < or <= condition instead.

sph•11mo ago
I have built a production Javascript library with decent amounts of users that incorporates the following hack to deal with float error (avert your eyes if you're sensitive):

  // 1.2 - 1.0 === 0.19999999999999996
  // fixFloatError(1.2 - 1.0) === 0.2
  var fixFloatError = function (n) {
    return parseFloat(n.toPrecision(12));
  };
It felt correct at the time, but after reading the article, I cringe at how fundamentally broken it is. I got away with it because the library is used to convert betting odds, which are mostly small floating point numbers, so the error is often < 10^-12.

Where the goblins came from

https://openai.com/index/where-the-goblins-came-from/
612•ilreb•6h ago•336 comments

Noctua releases official 3D CAD models for its cooling fans

https://www.noctua.at/en/3d-cad-models
244•embedding-shape•2d ago•49 comments

Zed 1.0

https://zed.dev/blog/zed-1-0
1853•salkahfi•19h ago•594 comments

The Zig project's rationale for their anti-AI contribution policy

https://simonwillison.net/2026/Apr/30/zig-anti-ai/
282•lumpa•7h ago•122 comments

Craig Venter has died

https://www.jcvi.org/media-center/j-craig-venter-genomics-pioneer-and-founder-jcvi-and-diploid-ge...
233•rdl•8h ago•41 comments

Mozilla's Opposition to Chrome's Prompt API

https://github.com/mozilla/standards-positions/issues/1213
65•jaffathecake•2h ago•17 comments

Copy Fail

https://copy.fail/
977•unsnap_biceps•15h ago•359 comments

Biology is a Burrito: A text- and visual-based journey through a living cell

https://burrito.bio/essays/biology-is-a-burrito
101•the-mitr•6h ago•13 comments

"Parse, don't validate" through the years with C++

https://derekrodriguez.dev/parse-dont-validate-through-the-years-with-c-/
15•dwrodri•2d ago•0 comments

Cursor Camp

https://neal.fun/cursor-camp/
949•bpierre•18h ago•152 comments

Alignment whack-a-mole: Finetuning activates recall of copyrighted books in LLMs

https://github.com/cauchy221/Alignment-Whack-a-Mole-Code
133•reconnecting•6h ago•101 comments

London to Calcutta by Bus (2022)

https://www.amusingplanet.com/2022/08/london-to-calcutta-by-bus.html
62•CGMthrowaway•1d ago•22 comments

OpenTrafficMap

https://opentrafficmap.org/
272•moooo99•14h ago•63 comments

FastCGI: 30 years old and still the better protocol for reverse proxies

https://www.agwa.name/blog/post/fastcgi_is_the_better_protocol_for_reverse_proxies
340•agwa•17h ago•78 comments

Functional programmers need to take a look at Zig

https://pure-systems.org/posts/2026-04-29-functional-programmers-need-to-take-a-look-at-zig.html
120•xngbuilds•6h ago•86 comments

Monad Tutorials Timeline

https://wiki.haskell.org/Monad_tutorials_timeline
35•brudgers•5h ago•10 comments

Mike: open-source legal AI

https://mikeoss.com/
95•noleary•9h ago•37 comments

HERMES.md in commit messages causes requests to route to extra usage billing

https://github.com/anthropics/claude-code/issues/53262
1133•homebrewer•15h ago•480 comments

Why I still reach for Lisp and Scheme instead of Haskell

https://jointhefreeworld.org/blog/articles/lisps/why-i-still-reach-for-scheme-instead-of-haskell/...
228•jjba23•1d ago•119 comments

Laws of UX

https://lawsofux.com/
268•bobbiechen•17h ago•40 comments

Creating a Color Palette from an Image

https://amandahinton.com/blog/creating-a-color-palette-from-an-image
74•evakhoury•1d ago•12 comments

An open-source stethoscope that costs between $2.5 and $5 to produce

https://github.com/GliaX/Stethoscope
255•0x54MUR41•19h ago•110 comments

DataCenter.FM – background noise app featuring the sound of the AI bubble

https://datacenter.fm/
9•louisbarclay•2h ago•1 comments

A 25-Year-Fight over a 2-Second Sample

https://www.plagiarismtoday.com/2026/04/20/a-25-year-fight-over-a-2-second-sample/
13•speckx•1d ago•0 comments

Joby kicks off NYC electric air taxi demos with historic JFK flight

https://www.flyingmag.com/joby-nyc-electric-air-taxi-jfk-airport/
49•Jblx2•9h ago•129 comments

Will you heed my warnings now?

https://scottaaronson.blog/?p=9718
56•bwesterb•3h ago•56 comments

Consequences of passing too few register parameters to a C function

https://devblogs.microsoft.com/oldnewthing/20260427-00/?p=112271
61•aragonite•2d ago•24 comments

Gooseworks (YC W23) Is Hiring a Founding Growth Engineer

https://www.ycombinator.com/companies/gooseworks/jobs/ztgY6bD-founding-growth-engineer
1•shivsak•12h ago

A grounded conceptual model for ownership types in Rust

https://cacm.acm.org/research-highlights/a-grounded-conceptual-model-for-ownership-types-in-rust/
36•tkhattra•8h ago•1 comments

I accidentally made law enforcement shut down their fake honeypot

https://lina.sh/blog/ddos-honeypot
117•fishgoesblub•13h ago•52 comments