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

Comments

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

FAWK: LLMs can write a language interpreter

https://martin.janiczek.cz/2025/11/21/fawk-llms-can-write-a-language-interpreter.html
78•todsacerdoti•3h ago•44 comments

Olmo 3: Charting a path through the model flow to lead open-source AI

https://allenai.org/blog/olmo3
191•mseri•6h ago•34 comments

It's hard to build an oscillator

https://lcamtuf.substack.com/p/its-hard-to-build-an-oscillator
97•chmaynard•5h ago•39 comments

Open Source and Local Code Mode MCP in Deno Sandboxes

https://portofcontext.com
18•pmkelly4444•1w ago•0 comments

Nano Banana Pro

https://blog.google/technology/ai/nano-banana-pro/
1102•meetpateltech•22h ago•626 comments

I converted a rotary phone into a meeting handset

https://www.stavros.io/posts/i-converted-a-rotary-phone-into-a-meeting-handset/
49•todsacerdoti•1w ago•19 comments

Android and iPhone users can now share files, starting with the Pixel 10

https://blog.google/products/android/quick-share-airdrop/
728•abraham•20h ago•425 comments

Brexit Hit to UK Economy Double Official Estimate, Study Finds

https://www.bloomberg.com/news/articles/2025-11-21/brexit-hit-to-uk-economy-double-official-estim...
67•donohoe•1h ago•48 comments

Roundtable (YC S23) Is Hiring Two Sales Development Representatives (SDRs)

https://www.ycombinator.com/companies/roundtable/jobs/irJTEsg-sales-development-representative
1•timshell•1h ago

How a French judge was digitally cut off by the USA

https://www.heise.de/en/news/How-a-French-judge-was-digitally-cut-off-by-the-USA-11087561.html
69•i-con•1h ago•26 comments

Scientists now know that bees can process time, a first in insects

https://www.cnn.com/2025/11/12/science/bees-visual-stimulus-study-scli-intl
41•Brajeshwar•6d ago•24 comments

FEX-emu – Run x86 applications on ARM64 Linux devices

https://fex-emu.com/
231•open-paren•1w ago•89 comments

WebAssembly from the Ground Up

https://wasmgroundup.com/
154•gurjeet•6d ago•36 comments

Show HN: 32V TENS device from built from scratch under $100

https://littlemountainman.github.io/2025/11/17/tens/
38•autonomydriver•3d ago•6 comments

New OS aims to provide (some) compatibility with macOS

https://github.com/ravynsoft/ravynos
258•kasajian•17h ago•122 comments

Over-regulation is doubling the cost

https://rein.pk/over-regulation-is-doubling-the-cost
243•bilsbie•14h ago•435 comments

HP and Dell disable HEVC support built into their laptops' CPUs

https://arstechnica.com/gadgets/2025/11/hp-and-dell-disable-hevc-support-built-into-their-laptops...
107•latexr•3h ago•69 comments

Okta's NextJS-0auth troubles

https://joshua.hu/ai-slop-okta-nextjs-0auth-security-vulnerability
330•ramimac•3d ago•121 comments

Data-at-Rest Encryption in DuckDB

https://duckdb.org/2025/11/19/encryption-in-duckdb
193•chmaynard•18h ago•21 comments

The Qtile Window Manager: A Python-Powered Tiling Experience

https://tech.stonecharioteer.com/posts/2025/qtile-window-manager/
22•stonecharioteer•5h ago•6 comments

NTSB Preliminary Report – UPS Boeing MD-11F Crash [pdf]

https://www.ntsb.gov/Documents/Prelimiary%20Report%20DCA26MA024.pdf
184•gregsadetsky•19h ago•199 comments

The Lions Operating System

https://lionsos.org
178•plunderer•19h ago•51 comments

Color Spaces, Bitmaps and Pumpkins

https://pmig96.wordpress.com/2025/11/12/color-spaces-bitmaps-and-pumpkins/
3•msephton•5d ago•0 comments

Free interactive tool that shows you how PCIe lanes work on motherboards

https://mobomaps.com
230•tagyro•2d ago•54 comments

Hilbert space: Treating functions as vectors

https://eli.thegreenplace.net/2025/hilbert-space-treating-functions-as-vectors/
81•signa11•1w ago•36 comments

Show HN: F32 – An Extremely Small ESP32 Board

https://github.com/PegorK/f32
263•pegor•1d ago•47 comments

Adversarial poetry as a universal single-turn jailbreak mechanism in LLMs

https://arxiv.org/abs/2511.15304
321•capgre•1d ago•161 comments

Show HN: My hobby OS that runs Minecraft

https://astral-os.org/posts/2025/10/31/astral-minecraft.html
200•avaliosdev•3d ago•24 comments

Two recently found works of J.S. Bach presented in Leipzig [video]

https://www.youtube.com/watch?v=4hXzUGYIL9M#t=15m19s
158•Archelaos•3d ago•100 comments

CBP is monitoring US drivers and detaining those with suspicious travel patterns

https://apnews.com/article/immigration-border-patrol-surveillance-drivers-ice-trump-9f5d05469ce8c...
748•jjwiseman•17h ago•792 comments