def siScale(x, minVal=1e-25, allowUnicode=True):
 if isinstance(x, decimal.Decimal):
  x = float(x)
 try:
  if (np.isnan(x) or np.isinf(x)):
   return (1, '')
 except:
  print (x, type(x))
  raise
 if (abs(x) < minVal):
  m = 0
  x = 0
 else:
  m = int(np.clip(np.floor((np.log(abs(x)) / np.log(1000))), (-9.0), 9.0))
 if (m == 0):
  pref = ''
 elif ((m < (-8)) or (m > 8)):
  pref = ('e%d' % (m * 3))
 elif allowUnicode:
  pref = SI_PREFIXES[(m + 8)]
 else:
  pref = SI_PREFIXES_ASCII[(m + 8)]
 p = (0.001 ** m)
 return (p, pref)

def siScale ( x , minVal = 1e-25 , allowUnicode = True ) : if isinstance ( x , decimal . Decimal ) : x = float ( x ) try : if ( np . isnan ( x ) or np . isinf ( x ) ) : return ( 1 , '' ) except : print ( x , type ( x ) ) raise if ( abs ( x ) < minVal ) : m = 0 x = 0 else : m = int ( np . clip ( np . floor ( ( np . log ( abs ( x ) ) / np . log ( 1000 ) ) ) , ( - 9.0 ) , 9.0 ) ) if ( m == 0 ) : pref = '' elif ( ( m < ( - 8 ) ) or ( m > 8 ) ) : pref = ( 'e%d' % ( m * 3 ) ) elif allowUnicode : pref = SI_PREFIXES [ ( m + 8 ) ] else : pref = SI_PREFIXES_ASCII [ ( m + 8 ) ] p = ( 0.001 ** m ) return ( p , pref )
return the recommended scale factor and si prefix string for x .