Skip to main content

scifloat

Alternative to conventional floats used for scientific measurements.

pip install scifloat

Quick start

from scifloat.scifloat import scifloat

s = round(scifloat(1.2421, 0.0513))
print(s)          # 1.24 ± 0.06

a = round(scifloat(1.36551315, [0.0302, 0.00891]))
print(a)  # 1.37 +0.04 | -0.01

Nothing is rounded until you call round() — scifloat(x, dx) just stores the raw value and error(s). x and dx can be ints, floats, or strings.

The two rounding rules

  1. Errors round up, to 2 significant digits if the leading digit is 1 or 2, otherwise to 1 (0.0111 → 0.012, 0.0513 → 0.06).
  2. The value rounds to the error's precision, using classic round-half-to-even (1.35 → 1.4, 1.25 → 1.2).

For an asymmetric error, the coarser (fewer decimal places) side sets the shared precision — pass match_precision=False to keep each side at its own precision instead.

Arithmetic

+ - * / between two scifloats propagate the errors in quadrature:

x = scifloat(10.5, 0.3)
y = scifloat(2.0, 0.1)
print(round(x + y))  # 12.5 ± 0.4
print(round(x / y))  # 5.2 ± 0.4

LaTeX export

s.to_latex()
# '$\\num[parse-numbers=false]{1.24 \\pm 0.06}$'

s.to_latex(symbol="x_obs", unit=r"\meter")
# '$x_{\\mathrm{obs}} = \\SI[parse-numbers=false]{1.24 \\pm 0.06}{\\meter}$'

More

See the tutorial notebook for a full walkthrough of both rounding rules, asymmetric errors, and every to_latex() option.

Metadata

Release files for scifloat 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scifloat 3.0.0
File Size Uploaded
scifloat-3.0.0.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scifloat 3.0.0
File Interpreter ABI Platform
scifloat-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.4 kB

Release files / scifloat-3.0.0.tar.gz

Download URL scifloat-3.0.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
15824055156ef2f3c99fad21b86e9fa902b934c66b43fe3825e854fbb15dd060
BLAKE2b-256 checksum
How to use checksums
694c5ed3d7f692c4355191daaa415880377b507ef0ce871f82af3fb0c8561248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / scifloat-3.0.0-py3-none-any.whl

Download URL scifloat-3.0.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a789b95ed435bff998cef00adf1edb8b3c5f0835176ebe72e027fca0a059806a
BLAKE2b-256 checksum
How to use checksums
78738c7e92dfce64410b9d6aeec14dcc746010dce61df77da819d3925ece2433
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page