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.

Ministry of Justice orders deletion of the UK's largest court reporting database

https://www.legalcheek.com/2026/02/ministry-of-justice-orders-deletion-of-the-uks-largest-court-r...
218•harel•2h ago•149 comments

The Sideprocalypse

https://johan.hal.se/wrote/2026/02/03/the-sideprocalypse/
53•headalgorithm•1h ago•31 comments

Running My Own XMPP Server

https://blog.dmcc.io/journal/xmpp-turn-stun-coturn-prosody/
91•speckx•2h ago•43 comments

What Your Bluetooth Devices Reveal About You

https://blog.dmcc.io/journal/2026-bluetooth-privacy-bluehood/
47•ssgodderidge•1h ago•12 comments

Ghidra by NSA

https://github.com/NationalSecurityAgency/ghidra
107•handfuloflight•2d ago•59 comments

Qwen3.5: Towards Native Multimodal Agents

https://qwen.ai/blog?id=qwen3.5
210•danielhanchen•6h ago•88 comments

I’m joining OpenAI

https://steipete.me/posts/2026/openclaw
1263•mfiguiere•18h ago•947 comments

I want to wash my car. The car wash is 50 meters away. Should I walk or drive?

https://mastodon.world/@knowmadd/116072773118828295
1013•novemp•9h ago•651 comments

MessageFormat: Unicode standard for localizable message strings

https://github.com/unicode-org/message-format-wg
120•todsacerdoti•5h ago•46 comments

Rolling your own serverless OCR in 40 lines of code

https://christopherkrapu.com/blog/2026/ocr-textbooks-modal-deepseek/
62•mpcsb•4d ago•29 comments

iOS 27 'Rave' Update to Clean Up Code, Could Boost Battery Life

https://www.macrumors.com/2026/02/16/apple-plans-snow-leopard-cleanup-ios-27/
63•tosh•1h ago•44 comments

Modern CSS Code Snippets: Stop writing CSS like it's 2015

https://modern-css.com
595•eustoria•22h ago•242 comments

Anthropic tries to hide Claude's AI actions. Devs hate it

https://www.theregister.com/2026/02/16/anthropic_claude_ai_edits/
181•beardyw•5h ago•121 comments

UK Discord users were part of a Peter Thiel-linked data collection experiment

https://www.rockpapershotgun.com/good-news-uk-discord-users-were-part-of-a-peter-thiel-linked-dat...
31•righthand•1h ago•0 comments

Vim-pencil: Rethinking Vim as a tool for writing

https://github.com/preservim/vim-pencil
87•gurjeet•3d ago•32 comments

Magnus Carlsen Wins the Freestyle (Chess960) World Championship

https://www.fide.com/magnus-carlsen-wins-2026-fide-freestyle-world-championship/
333•prophylaxis•17h ago•229 comments

Expensively Quadratic: The LLM Agent Cost Curve

https://blog.exe.dev/expensively-quadratic
97•luu•3d ago•51 comments

1,300-year-old world chronicle unearthed in Sinai

https://www.heritagedaily.com/2026/02/1300-year-old-world-chronicle-unearthed-in-sinai/156948
100•telotortium•4d ago•11 comments

picol: A Tcl interpreter in 500 lines of code

https://github.com/antirez/picol
88•tosh•8h ago•43 comments

LT6502: A 6502-based homebrew laptop

https://github.com/TechPaula/LT6502
390•classichasclass•23h ago•191 comments

Audio is the one area small labs are winning

https://www.amplifypartners.com/blog-posts/arming-the-rebels-with-gpus-gradium-kyutai-and-audio-ai
266•rocauc•3d ago•77 comments

Arm wants a bigger slice of the chip business

https://www.economist.com/business/2026/02/12/arm-wants-a-bigger-slice-of-the-chip-business
128•andsoitis•13h ago•81 comments

planckforth: Bootstrapping a Forth interpreter from hand-written tiny ELF binary

https://github.com/nineties/planckforth
10•tosh•4h ago•0 comments

Thanks a lot, AI: Hard drives are sold out for the year, says WD

https://mashable.com/article/ai-hard-drive-hdd-shortages-western-digital-sold-out
221•dClauzel•3h ago•177 comments

Intermittent fasting may make little difference to weight loss, review finds

https://www.bbc.co.uk/news/articles/c4ge7n3pq62o
9•fredley•56m ago•6 comments

Hard problems in social media archiving

https://alexwlchan.net/2025/hard-problems-in-social-media-archiving/
34•surprisetalk•4d ago•4 comments

I gave Claude access to my pen plotter

https://harmonique.one/posts/i-gave-claude-access-to-my-pen-plotter
252•futurecat•2d ago•165 comments

Show HN: Microgpt is a GPT you can visualize in the browser

https://microgpt.boratto.ca
250•b44•21h ago•23 comments

How DSQL makes sure sequences scale

https://blog.benjscho.dev/technical/2026/02/13/dsql-sequences.html
6•steepben•2d ago•1 comments

JavaScript-heavy approaches are not compatible with long-term performance goals

https://sgom.es/posts/2026-02-13-js-heavy-approaches-are-not-compatible-with-long-term-performanc...
140•luu•15h ago•157 comments