Skip to main content

Precision Levels

starward supports multiple precision levels for different use cases.

Available Levels

LevelDecimalsExampleUse Case
compact245.67°Quick reference
display445.6789°Readable output
standard645.678901°Default, general use
high1045.6789012345°Research
full1545.678901234567890°Maximum precision

CLI Usage

# Set precision for a command
starward --precision high sun position

# Short form
starward -p full planets position mars

# With aliases
starward -p compact p all

Python API

from starward import get_precision, set_precision, precision_context

# Check current precision
prec = get_precision()
print(f"Decimals: {prec.decimals}")

# Set globally
set_precision('high')

# Use context manager for temporary change
with precision_context('full'):
# High precision calculations here
pass
# Back to previous precision

PrecisionConfig

from starward.core.precision import PrecisionConfig, PrecisionLevel

# Get config for a level
config = PrecisionConfig.from_level(PrecisionLevel.HIGH)

# Properties
config.decimals # Number of decimal places
config.format_spec # Python format specifier

When to Use Each Level

Compact (2 decimals)

  • Quick observing checks
  • Rough planning
  • Display in tight spaces

Display (4 decimals)

  • General observation planning
  • Casual use
  • Documentation examples

Standard (6 decimals)

  • Default for most calculations
  • Rise/set times
  • Coordinate transformations

High (10 decimals)

  • Research applications
  • Comparing with catalogs
  • Precise ephemerides

Full (15 decimals)

  • Maximum precision needed
  • Algorithm verification
  • Cross-checking sources

Internal Precision

Note: Precision levels only affect output formatting. All internal calculations use full floating-point precision (64-bit IEEE 754). The precision setting determines how many decimal places are shown in results.

# Internal calculation is always full precision
sun = sun_position()

# Display precision affects formatting
set_precision('compact')
print(f"RA: {sun.ra.degrees:.{get_precision().decimals}f}°")
# Output: "RA: 45.67°"

set_precision('full')
print(f"RA: {sun.ra.degrees:.{get_precision().decimals}f}°")
# Output: "RA: 45.678901234567890°"