Skip to content
Novus Examples
csv729 B

Binary versus Decimal Arithmetic — Where Floats Disagree (.csv)

Eight arithmetic expressions where binary floating point and exact decimal disagree, with both answers and the signed error side by side. Adding one cent a hundred times does not give one, and this file says by exactly how much.

Preview — first 10 linescsv
expression,binary_float64_result,exact_decimal_result,error,note
0.1 + 0.2,0.30000000000000004,0.3,+5.5511151231257827e-17,the canonical example
1.1 * 3,3.3000000000000003,3.3,+4.4408920985006262e-16,repeated fraction in binary
0.01 summed 100 times,1.0000000000000007,1.0,+6.6613381477509392e-16,money loops accumulate error
2.675 rounded to 2 dp,2.67,2.68,-0.010000000000000231,2.675 is stored slightly below
0.1 + 0.7,0.7999999999999999,0.8,-1.1102230246251565e-16,another exact-looking sum that is not
1e16 + 1 - 1e16,0.0,1.0,-1,absorption: the 1 vanishes
(0.1 + 0.2) == 0.3,0.0,1.0,-1,equality on floats is the underlying bug
9007199254740993 as a double,9007199254740992.0,9007199254740993,+0,2^53 + 1 is not representable

Specifications

Rows
8
Columns
5
Cases
0.1+0.2, repeated fractions, cent accumulation, round-half, absorption, 2^53+1
Hundred Cent Sum
1.0000000000000007
Use Decimal Instead
the exact_decimal_result column is what a decimal type returns

Testing contract

Reference control
Scenario
Evaluate every expression in float64 and then in an exact decimal type, comparing both against the columns here.
Expected result
The float64 results match binary_float64_result exactly including 0.30000000000000004, while the decimal evaluation matches exact_decimal_result and the error column accounts for the gap.

What is a .csv file?

CSV (Comma-Separated Values) is a plain-text tabular format where rows are lines and fields are separated by commas, with quoting rules for values that contain delimiters, quotes, or newlines. It has no formal type system and depends on encoding and dialect conventions. It is the most portable format for tabular data exchange.

How to use this file

Use an example CSV to test parsers against quoting and embedded-delimiter edge cases, header handling, encoding detection, and import pipelines into databases or spreadsheets.

How to use this file for testing

“Binary versus Decimal Arithmetic — Where Floats Disagree (.csv)” is a deterministic Novus Examples fixture for Scientific data, CSV parsing, Editor testing. Citation catalogs (BibTeX, RIS), chemistry structures (MDL Molfile, PDB), and gridded binary data (NetCDF, FITS) — for testing reference managers, molecule viewers, and scientific-data loaders.

Documented properties for this file: 8 rows · 5 columns. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such — expect parsers to fail loudly rather than silently accept them.

Scientific fixtures are small, valid, and fully synthetic — no real organism, patient, sample, or observation. Point your parser or loader at the file and check it reads the documented records, variables, or headers; binary formats ship a readable twin or metadata listing for comparison.

Code examples

import pandas as pd

df = pd.read_csv("binary-versus-decimal-arithmetic.csv")
print(df.head())
print(df.dtypes)

Generated by generation/scientific.py. Free for any use, no attribution required — license.