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.

The workers behind Meta's smart glasses can see everything

https://www.svd.se/a/K8nrV4/metas-ai-smart-glasses-and-data-privacy-concerns-workers-say-we-see-e...
443•sandbach•2h ago•242 comments

Welcome (back) to Macintosh

https://take.surf/2026/03/01/welcome-back-to-macintosh
231•Udo_Schmitz•4h ago•138 comments

Seed of Might Color Correction Process (2023) [pdf]

https://andrewvanner.github.io/som/SoM_CC_Process_Day.pdf
59•haunter•2h ago•15 comments

Closure of the Weatheradio Service in Canada

https://www.rac.ca/rac-responds-to-the-closure-of-the-weatherradio-service-in-canada/
48•da768•2h ago•23 comments

The Case for Apolitical Tech Spaces

https://minor.gripe/posts/2026-03-02-the_case_for_apolitical_tech_spaces/
10•ai_critic•1h ago•7 comments

Show HN: I built a sub-500ms latency voice agent from scratch

https://www.ntik.me/posts/voice-agent
136•nicktikhonov•3h ago•36 comments

How to Build Your Own Quantum Computer

https://physics.aps.org/articles/v19/24
15•tzury•2h ago•1 comments

British Columbia to end time changes, adopt year-round daylight time

https://www.cbc.ca/news/canada/british-columbia/b-c-adopting-year-round-daylight-time-9.7111657
397•ireflect•4h ago•226 comments

First in-utero stem cell therapy for fetal spina bifida repair is safe: study

https://health.ucdavis.edu/news/headlines/first-ever-in-utero-stem-cell-therapy-for-fetal-spina-b...
246•gmays•10h ago•47 comments

New iPad Air, powered by M4

https://www.apple.com/newsroom/2026/03/apple-introduces-the-new-ipad-air-powered-by-m4/
313•Garbage•11h ago•516 comments

The 185-Microsecond Type Hint

https://blog.sturdystatistics.com/posts/type_hint/
36•kianN•3h ago•2 comments

RCade: Building a Community Arcade Cabinet

https://www.frankchiarulli.com/blog/building-the-rcade/
38•evakhoury•4d ago•3 comments

Show HN: Govbase – Follow a bill from source text to news bias to social posts

https://govbase.com
152•foxfoxx•8h ago•68 comments

Against Query Based Compilers

https://matklad.github.io/2026/02/25/against-query-based-compilers.html
11•surprisetalk•1d ago•1 comments

Programmable Cryptography

https://0xparc.org/writings/programmable-cryptography-1
37•fi-le•2d ago•22 comments

Show HN: Visual Lambda Calculus – a thesis project (2008) revived for the web

https://github.com/bntre/visual-lambda
15•bntr•2d ago•4 comments

Motorola announces a partnership with GrapheneOS

https://motorolanews.com/motorola-three-new-b2b-solutions-at-mwc-2026/
2051•km•18h ago•733 comments

"That Shape Had None" – A Horror of Substrate Independence (Short Fiction)

https://starlightconvenience.net/#that-shape-had-none
78•casmalia•6h ago•14 comments

Show HN: Pianoterm – Run shell commands from your Piano. A Linux CLI tool

https://github.com/vustagc/pianoterm
38•vustagc•4h ago•15 comments

Ask HN: Who is hiring? (March 2026)

163•whoishiring•9h ago•214 comments

Inside the M4 Apple Neural Engine, Part 1: Reverse Engineering

https://maderix.substack.com/p/inside-the-m4-apple-neural-engine
268•zdw•1d ago•67 comments

iPhone 17e

https://www.apple.com/newsroom/2026/03/apple-introduces-iphone-17e/
189•meetpateltech•11h ago•215 comments

Reflex (YC W23) Is Hiring Software Engineers – Python

https://www.ycombinator.com/companies/reflex/jobs
1•apetuskey•8h ago

LFortran compiles fpm

https://lfortran.org/blog/2026/02/lfortran-compiles-fpm/
46•wtlin•3d ago•20 comments

Launch HN: OctaPulse (YC W26) – Robotics and computer vision for fish farming

57•rohxnsxngh•8h ago•30 comments

Ask HN: Who wants to be hired? (March 2026)

64•whoishiring•9h ago•172 comments

Show HN: uBlock filter list to blur all Instagram Reels

https://gist.github.com/shraiwi/009c652da6ce8c99a6e1e0c86fe66886
96•shraiwi•5h ago•24 comments

Parallel coding agents with tmux and Markdown specs

https://schipper.ai/posts/parallel-coding-agents/
117•schipperai•10h ago•88 comments

Build your own Command Line with ANSI escape codes (2016)

https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
34•vinhnx•2d ago•12 comments

Microsoft Creative Writer (1993)

https://classicreload.com/play/win3x-creative-writer.html
8•bikeshaving•2h ago•4 comments