Floating-Point vs Rationals

Cluster focuses on debates about precision issues in floating-point arithmetic versus using rationals, fractions, or fixed-point for exact results in division and other operations, with references to languages like Python.

📉 Falling 0.4x Programming Languages
2,537
Comments
20
Years Active
5
Top Authors
#5548
Topic ID

Activity Over Time

2007
2
2008
11
2009
22
2010
38
2011
48
2012
72
2013
90
2014
94
2015
135
2016
118
2017
165
2018
193
2019
196
2020
200
2021
229
2022
197
2023
279
2024
264
2025
183
2026
1

Keywords

e.g CPU lang.org ABC division.html BigDecimal blogspot.com bugs.ruby i.e node.js floating point floating integer rational division numbers denominator decimal precision float

Sample Comments

spooneybarger Dec 30, 2010 View on HN

because integer and float math are very different.because for some, 1/3 should not be a float but a ratio. if precision matters, you need ratios not floats. however if you just want speed, you want floats.

John23832 Jan 4, 2024 View on HN

Because floating point math doesn't work the same as basic integer arithmetic? Divide two floating point numbers.

gumby Aug 27, 2021 View on HN

Or if you need rationals, use fixed point (unfortunately not native in many languages)

scaredginger Feb 8, 2023 View on HN

Wouldn't seriously suggest doing this, but rationals with big integers would have exact results for all the common operations

saagarjha Dec 2, 2019 View on HN

Right; for the former integer arithmetic won't do.

DannoHung Nov 21, 2012 View on HN

What every Computer Scientist should be asking about Floating-point arithmetic: Why aren't there types for fixed-point/rational arithmetic exposed by your language and/or standard library?

DaiPlusPlus Apr 9, 2024 View on HN

Arbitrary-precision real-number libraries would disagree with you there.

majewsky Nov 16, 2017 View on HN

What's wrong about just `float(a)/float(b)`?

lloeki Feb 3, 2012 View on HN

> it uses floating point numbers instead of rational numbers.import decimalimport fractions

enriquto Dec 3, 2019 View on HN

what do you mean by "rationals"? infinite precision? because finite precision rationals are not associative and much worse than floats in many senses.