src/pylib/numTypes/floats

Source   Edit  

Procs

func as_integer_ratio(self: float; n = halfHigh(int)): (int, int) {.
    ...raises: [ValueError], tags: [], forbids: [].}
see as_someinteger_ratio Source   Edit  
func as_someinteger_ratio[I: SomeInteger](self: float; n = halfHigh(I)): (I, I)

EXT. Calculates the best rational approximation of x, where the denominator is smaller than n (default is the largest possible I for maximal resolution),

The algorithm is from toRational of std/rationals, based on the theory of continued fractions. David Eppstein / UC Irvine / 8 Aug 1993 , but raises ValueError or OverflowDefect if x is NaN or Infinity.

Hint: due to lack of arbitrary length integers, its accuracy is not as high as Python's
Source   Edit  
func checked_as_integer_ratio(self: float): (int, int) {....raises: [ValueError],
    tags: [], forbids: [].}
EXT. like as_integer_ratio but raises OverflowDefect when cannot represent accurately. Source   Edit  
func float_fromhex(s: string): float {....raises: [ValueError, Exception],
                                       tags: [], forbids: [].}
Source   Edit  
func fromhex(_: typedesc[float]; s: string): float
Source   Edit  
func hex(x: float): PyStr {....raises: [Exception], tags: [], forbids: [].}
Source   Edit  
func is_integer(self: float): bool {....raises: [], tags: [], forbids: [].}
Source   Edit