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

Comments

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

Death to Scroll Fade

https://dbushell.com/2026/01/09/death-to-scroll-fade/
83•PaulHoule•1h ago•44 comments

A tiny, decentralised tool to explore the small web

https://codeberg.org/susam/wander
29•carte_blanche•49m ago•1 comments

Rob Pike's Rules of Programming (1989)

https://www.cs.unc.edu/~stotts/COMP590-059-f24/robsrules.html
552•vismit2000•6h ago•303 comments

Snowflake AI Escapes Sandbox and Executes Malware

https://www.promptarmor.com/resources/snowflake-ai-escapes-sandbox-and-executes-malware
39•ozgune•1h ago•7 comments

Nvidia NemoClaw

https://github.com/NVIDIA/NemoClaw
26•hmokiguess•1h ago•2 comments

Machine Payments Protocol (MPP)

https://stripe.com/blog/machine-payments-protocol
47•bpierre•1h ago•19 comments

Wander – A tiny, decentralised tool (just 2 files) to explore the small web

https://susam.net/wander/
18•oystersareyum•57m ago•4 comments

Nightingale – open-source karaoke app that works with any song on your computer

https://nightingale.cafe/
363•rzzzzru•8h ago•79 comments

Federal Cyber Experts Called Microsoft's Cloud "A Pile of Shit", yet Approved It

https://www.propublica.org/article/microsoft-cloud-fedramp-cybersecurity-government
201•hn_acker•2h ago•86 comments

A Tiny Camera Revealed a Hidden Passage in the Great Pyramid

https://modernengineeringmarvels.com/2026/03/13/a-tiny-camera-revealed-a-hidden-passage-in-the-gr...
74•Brajeshwar•4d ago•38 comments

Pandas Exercises for Data Analysis (Interactive)

https://machinelearningplus.com/python/101-pandas-exercises-python-interactive/
110•selva86•4d ago•30 comments

JPEG Compression

https://www.sophielwang.com/blog/jpeg
375•vinhnx•4d ago•100 comments

OpenRocket

https://openrocket.info/
18•zeristor•3d ago•1 comments

Meta will shut down VR Horizon Worlds access June 15

https://www.engadget.com/ar-vr/meta-will-shut-down-vr-horizon-worlds-access-in-june-222028919.html
38•bookofjoe•1h ago•8 comments

Write up of my homebrew CPU build

https://willwarren.com/2026/03/12/building-my-own-cpu-part-3-from-simulation-to-hardware/
185•wwarren•2d ago•26 comments

Mistral AI Releases Forge

https://mistral.ai/news/forge
655•pember•19h ago•163 comments

A ngrok-style secure tunnel server written in Rust and Open Source

https://github.com/joaoh82/rustunnel
32•joaoh82•2h ago•10 comments

A data center opened next door. Then came the high-pitched whine

https://www.politico.com/news/2026/03/11/data-centers-ai-electricity-virginia-00815219
16•1vuio0pswjnm7•39m ago•7 comments

Wide logging: Stripe's canonical log line pattern

https://blog.alcazarsec.com/tech/posts/wide-logging
4•alcazar•58m ago•0 comments

A Decade of Slug

https://terathon.com/blog/decade-slug.html
699•mwkaufma•21h ago•68 comments

Restoring the first recording of computer music (2018)

https://www.bl.uk/stories/blogs/posts/restoring-the-first-recording-of-computer-music
15•OJFord•4d ago•4 comments

Celebrating Tony Hoare's mark on computer science

https://bertrandmeyer.com/2026/03/16/celebrating-tony-hoares-mark-on-computer-science/
93•benhoyt•10h ago•25 comments

A Fuzzer for the Toy Optimizer

https://bernsteinbear.com/blog/toy-fuzzer/
7•surprisetalk•1d ago•1 comments

Ndea (YC W26) is hiring a symbolic RL search guidance lead

https://ndea.com/jobs/search-guidance
1•mikeknoop•9h ago

The pleasures of poor product design

https://www.inconspicuous.info/p/the-pleasures-of-poor-product-design
208•NaOH•15h ago•70 comments

Using calculus to do number theory

https://hidden-phenomena.com/articles/hensels
46•cpp_frog•2d ago•9 comments

On a Boat

https://moq.dev/blog/on-a-boat/
91•mmcclure•4d ago•20 comments

North Korean's 100k fake IT workers net $500M a year for Kim

https://www.theregister.com/2026/03/18/researchers_lift_the_lid_on/
9•speckx•46m ago•2 comments

Show HN: Sub-millisecond VM sandboxes using CoW memory forking

https://github.com/adammiribyan/zeroboot
251•adammiribyan•1d ago•62 comments

How the Eon Team Produced a Virtual Embodied Fly

https://eon.systems/updates/embodied-brain-emulation
64•LopRabbit•2d ago•18 comments