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.

Building and shipping Mac and iOS apps without opening Xcode

https://scottwillsey.com/building-and-shipping-mac-and-ios-apps-without-ever-opening-xcode/
282•speckx•6h ago•129 comments

What are Forward Deployed Engineers, and why are they so in demand? (2025)

https://newsletter.pragmaticengineer.com/p/forward-deployed-engineers
20•saisrirampur•1h ago•26 comments

Apple's new SpeechAnalyzer API, benchmarked against Whisper and its predecessor

https://get-inscribe.com/blog/apple-speech-api-benchmark.html
436•get-inscribe•8h ago•177 comments

An Englishwoman who sketched India before photography took hold

https://www.bbc.com/news/articles/cm2drrv6q54o
34•1659447091•1h ago•4 comments

N+1

https://www.woman-of-letters.com/p/n1
23•Caiero•4d ago•2 comments

The art and engineering of Sega CD Silpheed

https://fabiensanglard.net/silpheed/index.html
220•ibobev•10h ago•43 comments

Linux on the Sega 32X. Who needs hardware synchronization primitives anyway?

https://cakehonolulu.github.io/linux-on-32x/
97•cakehonolulu•6h ago•22 comments

The infinite scroll may become endangered if controversial Calif. law passes

https://www.sfgate.com/politics/article/meta-social-media-teenagers-22337724.php
67•Stratoscope•6h ago•109 comments

Show HN: YouTube Guitar Tab Parser

https://github.com/marcelpanse/youtube-guitar-tab-parser
64•neogenix•4h ago•46 comments

Mawlynnong, India, transformed by tourism, bans visitors on Sundays

https://www.bbc.com/travel/article/20260625-why-asias-cleanest-village-bans-tourists-on-sundays
58•gmays•2h ago•43 comments

Show HN: Jacquard, a programming language for AI-written, human-reviewed code

https://github.com/jbwinters/jacquard-lang
43•jbwinters•9h ago•17 comments

TFTP Honey Pot Results

https://bruceediger.com/posts/tftp-honeypot-results/
51•speckx•5h ago•24 comments

Telegram's t.me domain has been suspended

https://www.whois.com/whois/t.me
241•Tiberium•5h ago•177 comments

SalesPatriot (YC W25) Is Hiring Full Stack Engineers (SF)

https://jobs.ashbyhq.com/SalesPatriot/df223727-5781-433e-bc75-2aa5bf8dc8d7
1•maciejSz•4h ago

Samsung Health app threatens data deletion if users opt out AI training

https://neow.in/cWsyMTV3
249•bundie•5h ago•66 comments

Former NOAA employees built Climate.us to preserve climate data and resources

https://19thnews.org/2026/07/noaa-climate-data-website/
412•benwerd•5h ago•161 comments

Show HN: I implemented a neural network in SQL

https://github.com/xqlsystems/xarray-sql/blob/claude/xarray-sql-mnist-demo/benchmarks/nn.py
53•alxmrs•5h ago•12 comments

Ancient Roman Board Game

https://ludus-coriovalli.web.app/
87•nobody9999•4d ago•37 comments

Show HN: Hackney – Compare Uber, Lyft, Waymo, and Robotaxi Prices

https://hackney.app/
10•griffinli•10h ago•11 comments

A voxel Tokyo in real Japan time – ride the Yamanote line and study Japanese

https://jivx.com/densha
338•momentmaker•13h ago•67 comments

A Study of Microsoft's Early 2026 Rollout of Claude Code and GitHub Copilot CLI

https://arxiv.org/abs/2607.01418
18•softwaredoug•3h ago•7 comments

The AI Whale Fall and Open Source

https://minor.gripe/posts/2026-07-13-the_ai_whalefall_and_open_source/
5•ai_critic•1h ago•1 comments

Show HN: BillAI Bass, an AI-Powered Big Mouth Billy Bass Using Strands Agents

https://github.com/morganwilliscloud/billai-bass
57•mtw14•6h ago•25 comments

Robust Secret Storage in Networks

https://arxiv.org/abs/2606.30261
16•Anon84•5d ago•0 comments

Show HN: Nobie – an Excel-compatible runtime for agents and humans

https://nobie.com
75•matthewgapp•6h ago•39 comments

The 4-Bitter Lesson: Balancing Stability and Performance in NVFP4 RL

https://humansand.ai/blog/nvfp4-rl
23•Areibman•3d ago•3 comments

The Origins of Heikki's Garden of Flowers

https://garden-of-flowers.heikkilotvonen.com/?essay
25•panic•2d ago•2 comments

Show HN: Sigwire – a live TUI switchboard for every signal on your Linux box

https://github.com/yeet-src/sigwire
27•zasc•4h ago•10 comments

Collaboration Networks in Brazilian Computer Science

https://blog.ptidej.net/collaboration-networks-in-brazilian-computer-science/
11•aliiiimaher•3d ago•1 comments

Benchmarking 15 “E-Waste” GPUs with Modern Workloads

https://esologic.com/benchmarking-tesla-gpus/
113•eso_logic•11h ago•47 comments