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.

The Illustrated Transformer

https://jalammar.github.io/illustrated-transformer/
150•auraham•2h ago•33 comments

Ultrasound Cancer Treatment: Sound Waves Fight Tumors

https://spectrum.ieee.org/ultrasound-cancer-treatment
98•rbanffy•2h ago•27 comments

GLM-4.7: Advancing the Coding Capability

https://z.ai/blog/glm-4.7
145•pretext•3h ago•39 comments

The Garbage Collection Handbook

https://gchandbook.org/index.html
81•andsoitis•2h ago•3 comments

Claude Code gets native LSP support

https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md
230•JamesSwift•6h ago•129 comments

Feds demand compromise on Colorado River while states flounder

https://nevadacurrent.com/2025/12/22/feds-demand-compromise-on-colorado-river-states-flounder-des...
19•mooreds•1h ago•18 comments

Is the golden age of Indie software over?

https://successfulsoftware.net/2025/12/22/is-the-golden-age-of-indie-software-over/
21•hermitcrab•1h ago•13 comments

NIST was 5 μs off UTC after last week's power cut

https://www.jeffgeerling.com/blog/2025/nist-was-5-μs-utc-after-last-weeks-power-cut
116•jtokoph•5h ago•61 comments

Scaling LLMs to Larger Codebases

https://blog.kierangill.xyz/oversight-and-guidance
182•kierangill•6h ago•77 comments

Flock Exposed Its AI-Powered Cameras to the Internet. We Tracked Ourselves

https://www.404media.co/flock-exposed-its-ai-powered-cameras-to-the-internet-we-tracked-ourselves/
165•chaps•5h ago•249 comments

Things I learnt about passkeys when building passkeybot

https://enzom.dev/b/passkeys/
48•emadda•3h ago•13 comments

Your Supabase Is Public

https://skilldeliver.com/your-supabase-is-public
95•skilldeliver•5h ago•44 comments

The Rise of SQL:the second programming language everyone needs to know

https://spectrum.ieee.org/the-rise-of-sql
58•b-man•4d ago•46 comments

Hybrid Aerial Underwater Drone – Bachelor Project [video]

https://www.youtube.com/watch?v=g7vmPFZrYAk
22•nhma•13h ago•9 comments

US blocks all offshore wind construction, says reason is classified

https://arstechnica.com/science/2025/12/us-government-finds-new-excuse-to-stop-construction-of-of...
263•rbanffy•2h ago•212 comments

Uplane (YC F25) Is Hiring Founding Engineers (Full-Stack and AI)

https://www.useparallel.com/uplane1/careers
1•MarvinStarter•5h ago

Vince Zampella, developer of Call of Duty and Battlefield has died

https://comicbook.com/gaming/news/vince-zampella-developer-of-call-of-duty-and-battlefield-dead-a...
66•superpupervlad•1h ago•33 comments

In Pursuit of Clancy Sigal (2021)

https://yalereview.org/article/in-pursuit-of-clancy-sigal
6•dang•1h ago•0 comments

Show HN: It's Like Clay but in Google Sheets

https://www.getvurge.com/
6•rahulsingh34•4d ago•0 comments

How the RESISTORS put computing into 1960s counter-culture

https://spectrum.ieee.org/teenage-hackers
9•rbanffy•5d ago•1 comments

Jimmy Lai Is a Martyr for Freedom

https://reason.com/2025/12/19/jimmy-lai-is-a-martyr-for-freedom/
240•mooreds•5h ago•112 comments

The biggest CRT ever made: Sony's PVM-4300

https://dfarq.homeip.net/the-biggest-crt-ever-made-sonys-pvm-4300/
198•giuliomagnifico•9h ago•131 comments

Henge Finder

https://hengefinder.rcdis.co/#learn
35•recursecenter•4h ago•7 comments

Universal Reasoning Model (53.8% pass 1 ARC1 and 16.0% ARC 2)

https://arxiv.org/abs/2512.14693
15•marojejian•3h ago•2 comments

Debian's Git Transition

https://diziet.dreamwidth.org/20436.html
168•all-along•13h ago•55 comments

The ancient monuments saluting the winter solstice

https://www.bbc.com/culture/article/20251219-the-ancient-monuments-saluting-the-winter-solstice
157•1659447091•12h ago•84 comments

Programming languages used for music

https://timthompson.com/plum/cgi/showlist.cgi?sort=name&concise=yes
215•ofalkaed•2d ago•82 comments

State regulators vote to keep utility profits high angering customers across CA

https://www.latimes.com/environment/story/2025-12-18/state-regulators-vote-to-keep-utility-profit...
42•connor11528•3h ago•13 comments

There's no such thing as a fake feather [video]

https://www.youtube.com/watch?v=N5yV1Q9O6r4
62•surprisetalk•4d ago•24 comments

Show HN: Netrinos – A keep it simple Mesh VPN for small teams

https://netrinos.com
74•pcarroll•3d ago•42 comments