MCPcopy Create free account
hub / github.com/numpy/numpy / format_float

Function format_float

numpy/polynomial/polyutils.py:757–789  ·  view source on GitHub ↗
(x, parens=False)

Source from the content-addressed store, hash-verified

755
756
757def format_float(x, parens=False):
758 if not np.issubdtype(type(x), np.floating):
759 return str(x)
760
761 opts = np.get_printoptions()
762
763 if np.isnan(x):
764 return opts['nanstr']
765 elif np.isinf(x):
766 return opts['infstr']
767
768 exp_format = False
769 if x != 0:
770 a = absolute(x)
771 if a >= 1.e8 or a < 10**min(0, -(opts['precision']-1)//2):
772 exp_format = True
773
774 trim, unique = '0', True
775 if opts['floatmode'] == 'fixed':
776 trim, unique = 'k', False
777
778 if exp_format:
779 s = dragon4_scientific(x, precision=opts['precision'],
780 unique=unique, trim=trim,
781 sign=opts['sign'] == '+')
782 if parens:
783 s = '(' + s + ')'
784 else:
785 s = dragon4_positional(x, precision=opts['precision'],
786 fractional=True,
787 unique=unique, trim=trim,
788 sign=opts['sign'] == '+')
789 return s

Callers

nothing calls this directly

Calls 3

dragon4_scientificFunction · 0.90
dragon4_positionalFunction · 0.90
minFunction · 0.50

Tested by

no test coverage detected