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

Comments

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

Apple Photos App Corrupts Images

https://tenderlovemaking.com/2025/09/17/apple-photos-app-corrupts-images/
701•pattyj•6h ago•262 comments

Tinycolor Supply Chain Attack Post-Mortem

https://sigh.dev/posts/ctrl-tinycolor-post-mortem/
13•STRiDEX•24m ago•0 comments

Tau² Benchmark: How a Prompt Rewrite Boosted GPT-5-Mini by 22%

https://quesma.com/blog/tau2-benchmark-improving-results-smaller-models/
127•blndrt•4h ago•29 comments

Alibaba's new AI chip: Key specifications comparable to H20

https://news.futunn.com/en/post/62202518/alibaba-s-new-ai-chip-unveiled-key-specifications-compar...
196•dworks•7h ago•201 comments

Launch HN: RunRL (YC X25) – Reinforcement learning as a service

https://runrl.com
17•ag8•1h ago•2 comments

Determination of the fifth Busy Beaver value

https://arxiv.org/abs/2509.12337
202•marvinborner•7h ago•81 comments

Event Horizon Labs (YC W24) Is Hiring

https://www.ycombinator.com/companies/event-horizon-labs/jobs/U6oyyKZ-founding-engineer-at-event-...
1•ocolegro•43m ago

UUIDv47: Store UUIDv7 in DB, emit UUIDv4 outside (SipHash-masked timestamp)

https://github.com/stateless-me/uuidv47
72•aabbdev•3h ago•34 comments

GNU Midnight Commander

https://midnight-commander.org/
462•pykello•13h ago•258 comments

Microsoft Python Driver for SQL Server

https://github.com/microsoft/mssql-python
34•kermatt•2h ago•12 comments

Ask HN: What's a good 3D Printer for sub $1000?

22•lucideng•2d ago•17 comments

Procedural Island Generation (III)

https://brashandplucky.com/2025/09/17/procedural-island-generation-iii.html
70•ibobev•5h ago•11 comments

Shai-Hulud malware attack: Tinycolor and over 40 NPM packages compromised

https://socket.dev/blog/ongoing-supply-chain-attack-targets-crowdstrike-npm-packages
1182•jamesberthoty•1d ago•965 comments

PureVPN IPv6 Leak

https://anagogistis.com/posts/purevpn-ipv6-leak/
133•todsacerdoti•7h ago•59 comments

Drought in Iraq Reveals Ancient Tombs Created 2,300 Years Ago

https://www.smithsonianmag.com/smart-news/severe-droughts-in-iraq-reveals-dozens-of-ancient-tombs...
3•pseudolus•31m ago•0 comments

How to motivate yourself to do a thing you don't want to do

https://ashleyjanssen.com/how-to-motivate-yourself-to-do-a-thing-you-dont-want-to-do/
122•mooreds•2h ago•98 comments

YouTube addresses lower view counts which seem to be caused by ad blockers

https://9to5google.com/2025/09/16/youtube-lower-view-counts-ad-blockers/
126•iamflimflam1•3h ago•291 comments

Firefox 143 for Android to introduce DoH

https://blog.mozilla.org/en/firefox/dns-android/
151•HieronymusBosch•4h ago•83 comments

Stategraph: Terraform state as a distributed systems problem

https://stategraph.dev/blog/why-stategraph/
114•lawnchair•9h ago•54 comments

SQLiteData: A fast, lightweight replacement for SwiftData using SQL and CloudKit

https://github.com/pointfreeco/sqlite-data
28•wahnfrieden•4h ago•21 comments

Slow social media

https://herman.bearblog.dev/slow-social-media/
107•rishikeshs•15h ago•106 comments

Things you can do with a Software Defined Radio (2024)

https://blinry.org/50-things-with-sdr/
909•mihau•1d ago•151 comments

Notion API importer, with Databases to Bases conversion bounty

https://github.com/obsidianmd/obsidian-importer/issues/421
165•twapi•12h ago•54 comments

Doom crash after 2.5 years of real-world runtime confirmed on real hardware

https://lenowo.org/viewtopic.php?t=31
405•minki_the_avali•20h ago•172 comments

EU Chat Control: Germany's position has been reverted to undecided

https://mastodon.social/@chatcontrol/115215006562371435
334•doener•7h ago•240 comments

The Asus Gaming Laptop ACPI Firmware Bug: A Deep Technical Investigation

https://github.com/Zephkek/Asus-ROG-Aml-Deep-Dive
353•signa11•13h ago•155 comments

Murex – An intuitive and content aware shell for a modern command line

https://murex.rocks/
95•modinfo•11h ago•48 comments

You can't test if quantum uses complex numbers

https://algassert.com/post/2501
46•EvgeniyZh•2d ago•24 comments

Oh no, not again a meditation on NPM supply chain attacks

https://tane.dev/2025/09/oh-no-not-again...-a-meditation-on-npm-supply-chain-attacks/
147•theycameback•7h ago•173 comments

Ask HN: Is anyone else sick of AI splattered code

6•throwaway-ai-qs•13m ago•3 comments