simplebench.utils.significant_figures module🔗

Utility functions for significant figures handling.

simplebench.utils.significant_figures.sigfigs(number: float, figures: int = 3) float[source]🔗

Rounds a floating point number to the specified number of significant figures.

If the number of significant figures is not specified, it defaults to DEFAULT_SIGNIFICANT_FIGURES.

  • 14.2 to 2 digits of significant figures becomes 14

  • 0.234 to 2 digits of significant figures becomes 0.23

  • 0.0234 to 2 digits of significant figures becomes 0.023

  • 14.5 to 2 digits of significant figures becomes 15

  • 0.235 to 2 digits of significant figures becomes 0.24

Parameters:
  • number (float) – The number to round.

  • figures (int) – The number of significant figures to round to.

Raises:
  • TypeError – If the number arg is not a float or the figures arg is not an int.

  • ValueError – If the figures arg is not at least 1.

Returns:

The rounded number as a float.

Return type:

float