frontpage.
newsnewestaskshowjobs

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•1y ago

Comments

LegionMammal978•1y 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•1y 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•1y 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.

Lovable apps expose passport details and more than 200K private messages

https://www.crissyfield.de/research/lovable-en/
542•armcat•5h ago•199 comments

SpaceX Catches the Starship to end Flight 15

https://x.com/i/broadcasts/2brajgZlOKRMka
392•ls612•1h ago•215 comments

A Family Tree of Software Job Titles

https://zwischenzugs.com/2026/11/03/a-family-tree-of-software-job-titles/
159•umerf•5h ago•72 comments

KDE: The documentary [video]

https://tube.kockatoo.org/w/fFinNHfanLT7aBEb2B8y4c
339•mrkn1•9h ago•73 comments

PyPI's redesigned project pages with clearer security signals are now live

https://blog.pypi.org/posts/2026-11-06-ui-updates-complete/
180•rbanffy•7h ago•82 comments

'Grey Rocking': The Life-Improving Power of Being Really, Really Boring (2021)

https://www.esquire.com/uk/life/a38473153/grey-rock-technique-being-boring/
59•NaOH•2d ago•31 comments

Why get an expensive Pi when I have an old phone?

https://so.long.thanks.fish/why-pi-when-i-have-an-old-phone/
476•casi•4d ago•270 comments

Seagate's new hybrid drive raises some old questions

https://arstechnica.com/gadgets/2026/11/seagate-resurrects-the-ssd-hdd-hybrid-drive/
55•PaulHoule•3d ago•28 comments

Advancing science and engineering with Antigravity's /teamwork

https://research.google/blog/advancing-science-engineering-with-antigravitys-teamwork-feature/
146•acossta•9h ago•33 comments

Show HN: DeepSeek V3 in ~200 lines of pure Jax

https://github.com/Vaibhaav-Tiwari/deepseek-v3-jax
129•VaibhaavTiwari•7h ago•7 comments

Possible Futures

https://borretti.me/article/possible-futures
24•varjag•2d ago•15 comments

LinkedIn, Monster take down over 1000 fake job postings after CBC investigation

https://www.cbc.ca/news/canada/linkedin-monster-take-down-over-1-000-fake-job-postings-after-cbc-...
150•gnabgib•3h ago•65 comments

Reverse engineering a vintage diode-transistor logic chip

https://www.righto.com/2026/11/signetics-st680a-dtl-nand.html
78•dverlaeckt80•6d ago•4 comments

Generative AI uses more energy on non-English text

https://news.umich.edu/generative-ai-uses-more-energy-on-non-english-text/
163•DeepLogin•4d ago•90 comments

Show HN: A terminal-native idle factory game, written in Rust with ratatui

https://gitlab.com/snipedbywifi/terminactory
122•snipedbywifi•8h ago•24 comments

Project Zero will disclose vulnerabilities 90 days after reporting

https://projectzero.google/2026/11/disclosure-policy.html
114•hacb•11h ago•20 comments

The Sicilian Citrus Family Tree

https://www.notesfromtheroad.com/europa/citrus-family-tree.html
8•wmchen•3d ago•1 comments

Dartmouth (Guarini) will not admit math PhD cohort this year

https://www.thedartmouth.com/article/2026/11/gandhi-fagell-guarini-will-not-admit-math-ph-d-cohor...
55•sebg•3h ago•14 comments

Will we put data centers in space?

https://www.forethought.org/research/will-we-really-put-data-centers-in-space
45•simonebrunozzi•5h ago•139 comments

Demystifying phone unlocking tools: A technical overview

https://osservatorionessuno.org/blog/2026/05/demystifying-phone-unlocking-tools-a-technical-overv...
59•iloveyoutwo•8h ago•2 comments

Tech Companies Are Trying to Shift the Concept of Privacy (Again)

https://www.eff.org/deeplinks/2026/11/tech-companies-are-trying-shift-entire-concept-privacy-again
414•gslin•10h ago•159 comments

Show HN: Fursoy – Out-of-order RV64IMAFDV core in SystemVerilog (Linux 6.6)

https://github.com/FURSOY/fursoy-cpu
63•fursoy•8h ago•20 comments

A visual explanation of reinforcement learning

https://aatishb.com/myriad/how-brains-learn/
101•aatish•9h ago•6 comments

Italy fines Meta $887M over Android users' data access

https://www.reuters.com/world/italy-fines-meta-887-million-over-android-users-data-access-2026-11...
295•giuliomagnifico•9h ago•205 comments

Let's Write a PostScript Interpreter

https://beyondloom.com/blog/postscript.html
95•RebelPotato•1d ago•16 comments

Creating a self booting ZIP archive

https://goliath32.com/blog/ziphead.html
35•gdgghhhhh•6h ago•6 comments

Show HN: Agweb – a browser for agents that stays out of your way

https://github.com/paul-nameless/agweb
81•paul_nameless•8h ago•21 comments

US IRS free online tax filing open source repo (2025)

https://github.com/IRS-Public/direct-file
129•accountinhn•5h ago•77 comments

C3 0.8.6:Library fetching,30% smaller safe-mode binaries,and stricter type rules

https://c3-lang.org/blog/c3_0_8_6_fetching_libraries/
38•DASD•2d ago•1 comments

How to Create Your Own Decentralized Messenger Protocol

https://karboosx.net/post/5j7jdDM3/how-to-create-your-own-decentralized-messenger-protocol
49•fagnerbrack•6h ago•9 comments