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•9mo ago

Comments

LegionMammal978•9mo 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•9mo 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•9mo 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.

Never Buy A .online Domain

https://www.0xsid.com/blog/online-tld-is-pain
129•ssiddharth•32m ago•34 comments

Danish government agency to ditch Microsoft software (2025)

https://therecord.media/denmark-digital-agency-microsoft-digital-independence
348•robtherobber•3h ago•204 comments

Show HN: A real-time strategy game that AI agents can play

https://llmskirmish.com/
103•__cayenne__•4h ago•34 comments

How to fold the Blade Runner origami unicorn (1996)

https://web.archive.org/web/20011104015933/www.linkclub.or.jp/~null/index_br.html
59•exvi•2d ago•0 comments

100M-Row Challenge with PHP

https://github.com/tempestphp/100-million-row-challenge
58•brentroose•3h ago•15 comments

I'm helping my dog vibe code games

https://www.calebleak.com/posts/dog-game/
989•cleak•20h ago•319 comments

AIs can't stop recommending nuclear strikes in war game simulations

https://www.newscientist.com/article/2516885-ais-cant-stop-recommending-nuclear-strikes-in-war-ga...
24•ceejayoz•55m ago•15 comments

LLM=True

https://blog.codemine.be/posts/2026/20260222-be-quiet/
153•avh3•4h ago•103 comments

Claude Code Remote Control

https://code.claude.com/docs/en/remote-control
147•empressplay•6h ago•99 comments

Event Horizon Labs (YC W24) Is Hiring

https://www.ycombinator.com/companies/event-horizon-labs/jobs/xGQicps-founding-infrastructure-eng...
1•ocolegro•2h ago

Pi – A minimal terminal coding harness

https://pi.dev
460•kristianpaul•16h ago•221 comments

Turing Completeness of GNU find

https://arxiv.org/abs/2602.20762
79•todsacerdoti•8h ago•15 comments

Mercury 2: Fast reasoning LLM powered by diffusion

https://www.inceptionlabs.ai/blog/introducing-mercury-2
266•fittingopposite•15h ago•107 comments

Show HN: Moonshine Open-Weights STT models – higher accuracy than WhisperLargev3

https://github.com/moonshine-ai/moonshine
273•petewarden•16h ago•65 comments

Japanese Death Poems

https://www.secretorum.life/p/japanese-death-poems-part-3
73•NaOH•2d ago•21 comments

Mac mini will be made at a new facility in Houston

https://www.apple.com/newsroom/2026/02/apple-accelerates-us-manufacturing-with-mac-mini-production/
553•haunter•16h ago•556 comments

Hacking an old Kindle to display bus arrival times

https://www.mariannefeng.com/portfolio/kindle/
297•mengchengfeng•18h ago•75 comments

Cl-kawa: Scheme on Java on Common Lisp

https://github.com/atgreen/cl-kawa
53•varjag•3d ago•13 comments

I pitched a roller coaster to Disneyland at age 10 in 1978

https://wordglyph.xyz/one-piece-at-a-time
494•wordglyph•1d ago•179 comments

Nearby Glasses

https://github.com/yjeanrenaud/yj_nearbyglasses
371•zingerlio•20h ago•158 comments

Show HN: Scheme-langserver – Digest incomplete code with static analysis

https://github.com/ufo5260987423/scheme-langserver
15•ufo5260987423•1d ago•0 comments

Confusables.txt and NFKC disagree on 31 characters

https://paultendo.github.io/posts/unicode-confusables-nfkc-conflict/
3•pimterry•2d ago•0 comments

Show HN: Emdash – Open-source agentic development environment

https://github.com/generalaction/emdash
176•onecommit•20h ago•61 comments

Steel Bank Common Lisp

https://www.sbcl.org/
234•tosh•19h ago•97 comments

Amazon accused of widespread scheme to inflate prices across the economy

https://www.thebignewsletter.com/p/amazon-busted-for-widespread-price
529•toomuchtodo•13h ago•192 comments

Half million 'Words with Spaces' missing from dictionaries

https://www.linguabase.org/words-with-spaces.html
90•gligierko•1d ago•168 comments

Running RISC-V in a VM to test my snaps

https://blog.popey.com/2026/02/running-risc-v-in-a-vm-to-test-my-snaps/
12•jandeboevrie•3d ago•0 comments

Cell Service for the Fairly Paranoid

https://www.cape.co/
126•0xWTF•15h ago•121 comments

Meta problem with URPF our bundle in Boca raton

https://metafixthis.com/
47•synthesis5x•1d ago•5 comments

Anthropic Drops Flagship Safety Pledge

https://time.com/7380854/exclusive-anthropic-drops-flagship-safety-pledge/
444•cwwc•12h ago•213 comments