| | |

TOML 08 ๐Ÿ“„ High-Precision Numbers, Infinity, NaN, and Time Zones

โฑ๏ธ Estimated read: 8 min | |

TOML’s numeric and temporal types are precise by design, but the precision has limits that are easy to miss. Floats are recommended to be IEEE 754 binary64, but the specification uses “SHOULD,” which means a parser may offer higher precision through a different representation . Infinity and NaN are lowercase-only literals that map to special IEEE values. Dates and times come in four flavors, and only one of them carries a timezone offsetโ€”the other three are wall-clock values with no location.

This chapter covers the float precision boundary, the inf/nan literals, and the four date/time types with their timezone rules. It explains why tomllib recommends decimal.Decimal for financial data, why +nan and -nan are both just NaN, and why a local date-time is not an instant. The sections that follow walk through numbers and special values, the date/time taxonomy, and the offset rules that distinguish an absolute time from a wall-clock reading.

Key point: TOML floats are binary64 by recommendation, not requirement; inf and nan are lowercase literals; and only offset date-times carry a timezoneโ€”local date, local time, and local date-time are unanchored wall-clock values.


a. Float precision and the binary64 recommendation

TOML’s specification says floats “should be implemented as IEEE 754 binary64 values” . The word “should” is the escape hatch. A parser may use a higher-precision representation, and Python’s tomllib exposes this through the parse_float argument, which lets the caller pass a callable that converts the float’s string representation into a different type.

import tomllib
from decimal import Decimal

# Default: binary64 float (may lose precision)
data = tomllib.loads("price = 0.982492")

# Higher precision: parse as Decimal
data = tomllib.loads("price = 0.982492", parse_float=Decimal)
# data["price"] == Decimal("0.982492")

The tomli documentation notes that Decimal is “a practical choice for use cases where float inaccuracies can not be tolerated,” particularly in scientific and financial applications . The precision limit exists because binary64 cannot represent every decimal fraction exactly. A value like 0.1 is stored as an approximation, and arithmetic on approximations accumulates error. Parsing to Decimal preserves the decimal string the author wrote and performs exact decimal arithmetic.

The specification also states that if a value contains greater precision than the implementation can support, the additional precision must be truncated, not rounded . This is a strict rule: a parser that rounds 0.12345678901234567890 to the nearest binary64 instead of truncating is non-compliant. The truncation rule applies to the conversion from decimal text to the implementation’s internal representation, and it ensures that the parsed value never exceeds the author’s stated precision.


b. Infinity and NaN

TOML supports three special float values: inf (positive infinity), +inf (same), -inf (negative infinity), and nan (not a number). The +nan and -nan forms are also accepted . All of these are lowercase only. Inf, NaN, and NAN are not special values; they are bare keys or strings, and a bare key in value position produces a parse error.

# Valid special values
positive_inf = inf
explicit_inf = +inf
negative_inf = -inf
not_a_number = nan
explicit_nan = +nan
signed_nan = -nan

# INVALID: capitalized
# bad = Inf
# bad = NaN

The specification notes that the actual bit pattern of nan (whether it is a signaling NaN or a quiet NaN) is implementation-specific . The +nan and -nan forms are accepted but their expansion is also implementation-specific. This means a TOML file cannot rely on a specific NaN payload surviving a round trip.


c. The four date/time types and timezone rules

TOML defines four temporal types, distinguished by which components are present and whether a timezone offset is included. The offset is the only thing that makes a date-time an absolute instant; without it, the value is a wall-clock reading.

TypeExampleTimezone
Offset date-time1979-05-27T07:32:00ZYes (Z or ยฑHH:MM)
Local date-time1979-05-27T07:32:00No
Local date1979-05-27No
Local time07:32:00No

The timezone offset is written as Z (or z, case-insensitive) for UTC, or +HH:MM / -HH:MM for a positive or negative offset from UTC . An offset without a sign is invalid; 02:00 is not a timezone. The T separator between date and time may be replaced by a space, and fractional seconds are permitted with millisecond precision required and further precision implementation-specific .

# Offset date-times: absolute instants
utc = 1979-05-27T07:32:00Z
pacific = 1979-05-27T00:32:00-07:00
fractional = 1979-05-27T00:32:00.999999-07:00

# Local date-time: wall clock, no timezone
local_dt = 1979-05-27T07:32:00

# Local date: a day
local_date = 1979-05-27

# Local time: a time of day
local_time = 07:32:00

The Python mapping is direct: offset date-time becomes datetime.datetime with a timezone, local date-time becomes datetime.datetime with tzinfo=None, local date becomes datetime.date, and local time becomes datetime.time. A parser that attaches a timezone to a local date-time is wrong; the absence of an offset is the specification’s way of saying “this is not an instant.”


Complete Example Session

# ============================================
# PART 1: FLOAT PRECISION
# ============================================
pi = 3.14159265358979323846  # truncated to binary64 by parser
price = 0.982492             # parse with Decimal for exactness

# ============================================
# PART 2: SPECIAL VALUES
# ============================================
max_wait = inf
min_wait = -inf
undefined = nan

# ============================================
# PART 3: OFFSET DATE-TIME (ABSOLUTE)
# ============================================
created = 2026-05-05T10:00:00Z
updated = 2026-05-05T03:00:00-07:00

# ============================================
# PART 4: LOCAL DATE-TIME (WALL CLOCK)
# ============================================
alarm = 2026-05-05T07:30:00
# This is 7:30 AM wherever the reader is, not a fixed instant

# ============================================
# PART 5: LOCAL DATE AND TIME
# ============================================
birthday = 1990-01-15
opening = 09:00:00

# ============================================
# PART 6: PYTHON TYPE MAPPING
# ============================================
# created   โ†’ datetime(2026, 5, 5, 10, 0, tzinfo=timezone.utc)
# updated   โ†’ datetime(2026, 5, 5, 3, 0, tzinfo=timezone(-7h))
# alarm     โ†’ datetime(2026, 5, 5, 7, 30)  # tzinfo=None
# birthday  โ†’ date(1990, 1, 15)
# opening   โ†’ time(9, 0)

The parts covered float truncation, the special values, offset date-times as absolute instants, local date-times as wall-clock values, the date and time types, and the Python type mapping.


Quick Reference

Float Rules

RuleDetail
Recommended typeIEEE 754 binary64
Higher precisionVia parse_float in Python
Excess precisionTruncated, not rounded
Special valuesinf, +inf, -inf, nan

Date/Time Types

TypeComponentsTimezone
Offset date-timeDate + time + offsetYes
Local date-timeDate + timeNo
Local dateDateNo
Local timeTimeNo

Offset Syntax

FormMeaning
Z or zUTC
+HH:MMPositive offset from UTC
-HH:MMNegative offset from UTC
No offsetLocal (wall clock)

Best Practices

โœ… Do This:

# Use offset date-time for absolute instants
created = 2026-05-05T10:00:00Z                               # โœ…

# Use local date-time for recurring wall-clock schedules
alarm = 07:30:00                                             # โœ…

# Parse floats as Decimal for financial data
# tomllib.loads(..., parse_float=Decimal)                    # โœ…

# Use lowercase special values
timeout = inf                                                # โœ…

โŒ Don’t Do This:

# Assume local date-time is UTC
alarm = 2026-05-05T07:30:00  # no timezone, not an instant    # โŒ

# Use capitalized special values
# bad = Inf                                                  # โŒ

# Expect exact decimal precision from binary64
price = 0.1  # binary64 approximation                         # โŒ

# Attach a timezone to a local value in code
# (parser should return tzinfo=None)                          # โŒ

Common Pitfalls

PitfallWhy It HappensFix
Financial rounding errorsbinary64 approximationParse as Decimal
Inf rejectedCapitalizedUse inf
Local time treated as UTCNo offset in fileAdd Z or offset for instants
Date comparison failsLocal date is date, not datetimeCheck the type after parsing

Real-World Examples

1. Binary64 float

pi = 3.1415

2. Decimal parse in Python

tomllib.loads("price = 0.982492", parse_float=Decimal)

3. Positive infinity

max = inf

4. Negative infinity

min = -inf

5. NaN

undefined = nan

6. Offset date-time UTC

created = 2026-05-05T10:00:00Z

7. Offset date-time with zone

created = 2026-05-05T03:00:00-07:00

8. Local date-time

alarm = 2026-05-05T07:30:00

9. Local date

birthday = 1990-01-15

10. Local time

opening = 09:00:00

Visual

Float Precision Boundary

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  TOML FLOAT                                             โ”‚
โ”‚                                                         โ”‚
โ”‚  Text: "0.982492"                                       โ”‚
โ”‚         โ”‚                                               โ”‚
โ”‚         โ–ผ                                               โ”‚
โ”‚  Default parse: binary64 float                          โ”‚
โ”‚  โ†’ approximation (tiny error possible)                  โ”‚
โ”‚                                                         โ”‚
โ”‚  parse_float=Decimal                                    โ”‚
โ”‚  โ†’ exact decimal "0.982492"                             โ”‚
โ”‚                                                         โ”‚
โ”‚  Spec: binary64 is SHOULD, not MUST                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Date/Time Taxonomy

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  DATE/TIME TYPES                                        โ”‚
โ”‚                                                         โ”‚
โ”‚  Has offset?                                            โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                       โ”‚
โ”‚  โ”‚ 2026-05-05T  โ”‚                                       โ”‚
โ”‚  โ”‚ 10:00:00Z    โ”‚โ”€โ”€โ”€โ”€โ–บ OFFSET DATE-TIME (absolute)     โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                       โ”‚
โ”‚                                                         โ”‚
โ”‚  No offset, has date and time?                          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                       โ”‚
โ”‚  โ”‚ 2026-05-05T  โ”‚โ”€โ”€โ”€โ”€โ–บ LOCAL DATE-TIME (wall clock)     โ”‚
โ”‚  โ”‚ 10:00:00     โ”‚                                       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                       โ”‚
โ”‚                                                         โ”‚
โ”‚  Date only?                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                       โ”‚
โ”‚  โ”‚ 2026-05-05   โ”‚โ”€โ”€โ”€โ”€โ–บ LOCAL DATE                       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                       โ”‚
โ”‚                                                         โ”‚
โ”‚  Time only?                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                       โ”‚
โ”‚  โ”‚ 10:00:00     โ”‚โ”€โ”€โ”€โ”€โ–บ LOCAL TIME                       โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Timezone Offset Syntax

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  VALID OFFSETS                                          โ”‚
โ”‚                                                         โ”‚
โ”‚  Z or z  โ†’ UTC                                          โ”‚
โ”‚  +00:00  โ†’ UTC (explicit)                               โ”‚
โ”‚  +05:30  โ†’ India Standard Time                          โ”‚
โ”‚  -07:00  โ†’ Pacific Daylight Time                        โ”‚
โ”‚                                                         โ”‚
โ”‚  INVALID                                                โ”‚
โ”‚  02:00   โ†’ no sign, not a timezone                      โ”‚
โ”‚  +2:00   โ†’ hour must be two digits                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
Float recommendationIEEE 754 binary64
Higher precisionparse_float=Decimal
Excess precisionTruncated
Special valuesinf, -inf, nan (lowercase)
Offset date-timeHas Z or ยฑHH:MM
Local date-timeNo offset, wall clock
Local date/timeDate or time only
Offset without signInvalid

Key takeaways:

  • Binary64 is a recommendation, not a requirement. The specification uses “SHOULD,” and Python’s tomllib exposes parse_float to parse into Decimal for exact decimal arithmetic .
  • Excess float precision must be truncated, not rounded. A parser that rounds a decimal string to the nearest binary64 instead of truncating is non-compliant .
  • inf and nan are lowercase-only. Capitalized forms are not special values. The +nan and -nan forms are accepted but their expansion is implementation-specific .
  • Only offset date-times are absolute instants. Local date-times, local dates, and local times have no timezone; they are wall-clock values that require context to become instants.
  • The offset requires a sign. Z or ยฑHH:MM is a timezone; 02:00 without a sign is not .

Remember: TOML’s numeric and temporal types are precise in their syntax and bounded in their precision. Floats approximate unless parsed as decimals; infinity and NaN are lowercase literals with implementation-defined bit patterns; and a date-time without an offset is not an instant. When the value mattersโ€”money, scientific measurements, cross-timezone schedulingโ€”choose the representation that preserves it: Decimal for floats, offset date-times for instants, and local types only for values that are genuinely local.

Was this helpful?


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!