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

Comments

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

Accepting US car standards would risk European lives

https://etsc.eu/accepting-us-car-standards-would-risk-european-lives-warn-cities-and-civil-society/
418•saubeidl•2h ago•303 comments

Anthropic acquires Bun

https://bun.com/blog/bun-joins-anthropic
1818•ryanvogel•15h ago•858 comments

Zig quits GitHub, says Microsoft's AI obsession has ruined the service

https://www.theregister.com/2025/12/02/zig_quits_github_microsoft_ai_obsession/
199•Brajeshwar•2h ago•86 comments

IBM CEO says there is 'no way' spending on AI data centers will pay off

https://www.businessinsider.com/ibm-ceo-big-tech-ai-capex-data-center-spending-2025-12
537•nabla9•15h ago•611 comments

Interview with RollerCoaster Tycoon's Creator, Chris Sawyer (2024)

https://medium.com/atari-club/interview-with-rollercoaster-tycoons-creator-chris-sawyer-684a0efb0f13
90•areoform•5h ago•17 comments

The Writing Is on the Wall for Handwriting Recognition

https://newsletter.dancohen.org/archive/the-writing-is-on-the-wall-for-handwriting-recognition/
34•speckx•6d ago•8 comments

AI agents break rules under everyday pressure

https://spectrum.ieee.org/ai-agents-safety
134•pseudolus•5d ago•44 comments

Super fast aggregations in PostgreSQL 19

https://www.cybertec-postgresql.com/en/super-fast-aggregations-in-postgresql-19/
70•jnord•1w ago•4 comments

Quad9 DOH HTTP/1.1 Retirement, December 15, 2025

https://quad9.net/news/blog/doh-http-1-1-retirement/
55•pickledoyster•3h ago•13 comments

Paged Out

https://pagedout.institute
409•varjag•13h ago•49 comments

Trying Out C++26 Executors

https://mropert.github.io/2025/11/21/trying_out_stdexec/
7•ingve•5d ago•1 comments

Understanding ECDSA

https://avidthinker.github.io/2025/11/28/understanding-ecdsa/
63•avidthinker•5h ago•11 comments

OpenAI declares 'code red' as Google catches up in AI race

https://www.theverge.com/news/836212/openai-code-red-chatgpt
660•goplayoutside•19h ago•723 comments

I designed and printed a custom nose guard to help my dog with DLE

https://snoutcover.com/billie-story
515•ragswag•3d ago•62 comments

What, if anything, is universal to music cognition? (2024)

https://www.nature.com/articles/s41562-023-01800-9
16•Hooke•1w ago•6 comments

Sending DMARC reports is somewhat hazardous

https://utcc.utoronto.ca/~cks/space/blog/spam/DMARCSendingReportsProblems
41•zdw•4h ago•8 comments

Learning music with Strudel

https://terryds.notion.site/Learning-Music-with-Strudel-2ac98431b24180deb890cc7de667ea92
484•terryds•1w ago•118 comments

Researchers Find Microbe Capable of Producing Oxygen from Martian Soil

https://scienceclock.com/microbe-that-could-turn-martian-dust-into-oxygen/
17•ashishgupta2209•3h ago•6 comments

Counter Galois Onion: Improved encryption for Tor circuit traffic

https://blog.torproject.org/introducing-cgo/
74•wrayjustin•1w ago•14 comments

Qwen3-VL can scan two-hour videos and pinpoint nearly every detail

https://the-decoder.com/qwen3-vl-can-scan-two-hour-videos-and-pinpoint-nearly-every-detail/
190•thm•3d ago•58 comments

Amazon launches Trainium3

https://techcrunch.com/2025/12/02/amazon-releases-an-impressive-new-ai-chip-and-teases-a-nvidia-f...
175•thnaks•14h ago•65 comments

Codeberg Is Down

https://status.codeberg.org/status/codeberg
25•x3ro•1h ago•9 comments

Japanese game devs face font dilemma as license increases from $380 to $20k

https://www.gamesindustry.biz/japanese-devs-face-font-licensing-dilemma-as-leading-provider-incre...
234•zdw•6h ago•115 comments

Zig's new plan for asynchronous programs

https://lwn.net/SubscriberLink/1046084/4c048ee008e1c70e/
285•messe•19h ago•208 comments

Load ZX Spectrum – first Museum dedicated to our first personal computer

https://loadzx.com/en/
51•elvis70•6d ago•14 comments

All about automotive lidar

https://mainstreetautonomy.com/blog/2025-08-29-all-about-automotive-lidar/
155•dllu•1d ago•63 comments

School cell phone bans and student achievement

https://www.nber.org/digest/202512/school-cell-phone-bans-and-student-achievement
154•harias•16h ago•149 comments

Free static site generator for small restaurants and cafes

https://lite.localcafe.org/
140•fullstacking•13h ago•78 comments

All Sources of DirectX 12 Documentation

https://asawicki.info/news_1794_all_sources_of_directx_12_documentation
22•ibobev•1w ago•10 comments

Kohler Can Access Pictures from "End-to-End Encrypted" Toilet Camera

https://varlogsimon.leaflet.pub/3m6zrw6k2bs2p?interactionDrawer=quotes
181•TimDotC•7h ago•159 comments