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

Comments

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

Growing up in “404 Not Found”: China's nuclear city in the Gobi Desert

https://substack.com/inbox/post/182743659
375•Vincent_Yan404•10h ago•143 comments

Calendar

https://neatnik.net/calendar/?year=2026
704•twapi•12h ago•90 comments

Hungry Fat Cells Could Someday Starve Cancer to Death

https://www.ucsf.edu/news/2025/01/429411/how-hungry-fat-cells-could-someday-starve-cancer-death
74•mrtnmrtn•7h ago•20 comments

Replacing JavaScript with Just HTML

https://www.htmhell.dev/adventcalendar/2025/27/
546•soheilpro•15h ago•194 comments

Building a macOS app to know when my Mac is thermal throttling

https://stanislas.blog/2025/12/macos-thermal-throttling-app/
66•angristan•5h ago•28 comments

One year of keeping a tada list

https://www.ducktyped.org/p/one-year-of-keeping-a-tada-list
105•egonschiele•6d ago•35 comments

Designing Predictable LLM-Verifier Systems for Formal Method Guarantee

https://arxiv.org/abs/2512.02080
9•PaulHoule•2h ago•0 comments

Floor796

https://floor796.com/
870•krtkush•1d ago•106 comments

Rex is a safe kernel extension framework that allows Rust in the place of eBPF

https://github.com/rex-rs/rex
102•zdw•5d ago•53 comments

Scientists discover beer bottle in the Mariana Trench (2024)

https://www.unilad.com/news/scientist-beer-bottle-deepest-point-ocean-mariana-trench-667878-20240213
16•thunderbong•35m ago•10 comments

How we lost communication to entertainment

https://ploum.net/2025-12-15-communication-entertainment.html
565•8organicbits•20h ago•303 comments

Langfuse (YC W23) Is Hiring in Berlin, Germany

https://langfuse.com/careers
1•clemo_ra•5h ago

Never Use Pixelation to Hide Sensitive Text (2014)

https://dheera.net/posts/20140725-why-you-should-never-use-pixelation/
20•basilikum•1w ago•7 comments

Fathers’ choices may be packaged and passed down in sperm RNA

https://www.quantamagazine.org/how-dads-fitness-may-be-packaged-and-passed-down-in-sperm-rna-2025...
240•vismit2000•15h ago•149 comments

Dialtone – AOL 3.0 Server

https://dialtone.live/
85•rickcarlino•13h ago•38 comments

Gpg.fail

https://gpg.fail
405•todsacerdoti•23h ago•234 comments

Last Year on My Mac: Look Back in Disbelief

https://eclecticlight.co/2025/12/28/last-year-on-my-mac-look-back-in-disbelief/
148•vitosartori•6h ago•92 comments

Streaming Uploads with LiveView

https://fly.io/phoenix-files/streaming-uploads-with-liveview/
3•m5r•6d ago•0 comments

'PromptQuest' is the worst game of 2025 (trying to make chatbots work)

https://www.theregister.com/2025/12/26/ai_is_like_adventure_games/
23•dijksterhuis•3h ago•16 comments

Functional programming and reliability: ADTs, safety, critical infrastructure

https://blog.rastrian.dev/post/why-reliability-demands-functional-programming-adts-safety-and-cri...
121•rastrian•16h ago•114 comments

Rainbow Six Siege hacked as players get billions of credits and random bans

https://www.shanethegamer.com/esports-news/rainbow-six-siege-hacked-global-server-outage/
244•erhuve•21h ago•100 comments

The Origins of APL (1974) [video]

https://www.youtube.com/watch?v=8kUQWuK1L4w
41•ofalkaed•6d ago•6 comments

Project Vend: Phase Two

https://www.anthropic.com/research/project-vend-2
161•kubami•6d ago•69 comments

William Golding's Island of Savagery

https://www.historytoday.com/archive/portrait-author-historian/william-goldings-island-savagery
30•samclemens•1w ago•38 comments

Windows 2 for the Apricot PC/Xi

https://www.ninakalinina.com/notes/win2apri/
149•todsacerdoti•22h ago•35 comments

Text rendering hates you (2019)

https://faultlore.com/blah/text-hates-you/
165•andsoitis•6d ago•69 comments

Immer – A library of persistent and immutable data structures written in C++

https://github.com/arximboldi/immer
110•smartmic•6d ago•12 comments

Show HN: Ez FFmpeg – Video editing in plain English

http://npmjs.com/package/ezff
385•josharsh•1d ago•190 comments

Liberating Bluetooth on the ESP32

https://exquisite.tube/w/mEzF442Q4hUXnhQ8HmfZuq
105•todsacerdoti•18h ago•17 comments

Say No to Palantir in the NHS

https://notopalantir.goodlawproject.org/email-to-target/stop-palantir-in-the-nhs/
498•_____k•19h ago•172 comments