Skip to content

Commit

Permalink
Add ndigits util
Browse files Browse the repository at this point in the history
  • Loading branch information
Setsugennoao committed Jul 15, 2024
1 parent 0e6b247 commit ec8b044
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions stgpytools/utils/math.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from math import ceil, log
from math import ceil, log, log10
from typing import Sequence

from ..types import Nb
Expand All @@ -14,7 +14,9 @@

'next_power_of_y', 'next_power_of_2',

'spline_coeff'
'spline_coeff',

'ndigits'
]


Expand Down Expand Up @@ -147,3 +149,10 @@ def spline_coeff(
s -= (py[i] / h - h * matrix[i][length] / 6) * (x - px[j])

return s


def ndigits(num: Nb) -> int:
if num == 0:
return 1

return int(log10(abs(num))) + 1

0 comments on commit ec8b044

Please sign in to comment.