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

Size of Life

https://neal.fun/size-of-life/
1529•eatonphil•11h ago•188 comments

Getting a Gemini API key is an exercise in frustration

https://ankursethi.com/blog/gemini-api-key-frustration/
317•speckx•7h ago•127 comments

Australia begins enforcing world-first teen social media ban

https://www.reuters.com/legal/litigation/australia-social-media-ban-takes-effect-world-first-2025...
614•chirau•1d ago•995 comments

Patterns.dev

https://www.patterns.dev/
46•handfuloflight•2h ago•15 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
341•__rito__•10h ago•163 comments

VCMI: An open-source engine for Heroes III

https://vcmi.eu/
23•eamag•4d ago•4 comments

Super Mario 64 for the PS1

https://github.com/malucard/sm64-psx
183•LaserDiscMan•9h ago•64 comments

Fossils reveal anacondas have been giants for over 12 million years

https://www.cam.ac.uk/stories/twelve-million-years-of-giant-anacondas
10•ashishgupta2209•1w ago•2 comments

How Google Maps allocates survival across London's restaurants

https://laurenleek.substack.com/p/how-google-maps-quietly-allocates
156•justincormack•1d ago•81 comments

Qwen3-Omni-Flash-2025-12-01:a next-generation native multimodal large model

https://qwen.ai/blog?id=qwen3-omni-flash-20251201
215•pretext•11h ago•86 comments

Rubio stages font coup: Times New Roman ousts Calibri

https://www.reuters.com/world/us/rubio-stages-font-coup-times-new-roman-ousts-calibri-2025-12-09/
188•italophil•1d ago•299 comments

Show HN: Automated license plate reader coverage in the USA

https://alpranalysis.com
130•sodality2•10h ago•84 comments

Common Lisp, ASDF, and Quicklisp: packaging explained

https://cdegroot.com/programming/commonlisp/2025/11/26/cl-ql-asdf.html
52•todsacerdoti•16h ago•13 comments

Gundam is just the same as Jane Austen but happens to include giant mech suits

https://eli.li/gundam-is-just-the-same-as-jane-austen-but-happens-to-include-giant-mech-suits
167•surprisetalk•1w ago•117 comments

When would you ever want bubblesort? (2023)

https://buttondown.com/hillelwayne/archive/when-would-you-ever-want-bubblesort/
69•atan2•6h ago•45 comments

Terrain Diffusion: A Diffusion-Based Successor to Perlin Noise

https://arxiv.org/abs/2512.08309
105•kelseyfrog•9h ago•31 comments

Scientists create ultra fast memory using light

https://www.isi.edu/news/81186/scientists-create-ultra-fast-memory-using-light/
73•giuliomagnifico•6d ago•16 comments

Valve: HDMI Forum Continues to Block HDMI 2.1 for Linux

https://www.heise.de/en/news/Valve-HDMI-Forum-Continues-to-Block-HDMI-2-1-for-Linux-11107440.html
564•OsrsNeedsf2P•10h ago•319 comments

The future of Terraform CDK

https://github.com/hashicorp/terraform-cdk
91•mfornasa•8h ago•96 comments

Is it a bubble?

https://www.oaktreecapital.com/insights/memo/is-it-a-bubble
169•saigrandhi•10h ago•252 comments

Launch HN: InspectMind (YC W24) – AI agent for reviewing construction drawings

43•aakashprasad91•11h ago•44 comments

RoboCrop: Teaching robots how to pick tomatoes

https://phys.org/news/2025-12-robocrop-robots-tomatoes.html
74•smurda•12h ago•35 comments

Golang's big miss on memory arenas

https://avittig.medium.com/golangs-big-miss-on-memory-arenas-f1375524cc90
105•andr3wV•1w ago•85 comments

Typewriter Plotters (2022)

https://biosrhythm.com/?p=2143
105•LaSombra•5d ago•7 comments

9 Mothers (YC X26) Is Hiring

https://app.dover.com/jobs/9mothers
1•ukd1•10h ago

Show HN: A 2-row, 16-key keyboard designed for smartphones

https://k-keyboard.com/Why-QWERTY-mini
54•QWERTYmini•10h ago•48 comments

Show HN: VoxCSS – A DOM based voxel engine

https://github.com/LayoutitStudio/voxcss
35•rofko•1w ago•5 comments

OpenRouter Broadcast

https://openrouter.ai/docs/guides/features/broadcast/overview
20•Topfi•4d ago•7 comments

Factor 0.101 now available

https://re.factorcode.org/2025/12/factor-0-101-now-available.html
109•birdculture•16h ago•12 comments

DeepSeek uses banned Nvidia chips for AI model, report says

https://finance.yahoo.com/news/china-deepseek-uses-banned-nvidia-131207746.html
290•goodway•11h ago•274 comments