Description

Parse parses s which must contain a text representation of a floating- point number with a mantissa in the given conversion base (the exponent is always a decimal number), or a string representing an infinite value.

It sets z to the (possibly rounded) value of the corresponding floating- point value, and returns z, the actual base b, and an error err, if any. If z's precision is 0, it is changed to 64 before rounding takes effect. The number must be of the form:

	number   = [ sign ] [ prefix ] mantissa [ exponent ] | infinity .
	sign     = "+" | "-" .
     prefix   = "0" ( "x" | "X" | "b" | "B" ) .
	mantissa = digits | digits "." [ digits ] | "." digits .
	exponent = ( "E" | "e" | "p" ) [ sign ] digits .
	digits   = digit { digit } .
	digit    = "0" ... "9" | "a" ... "z" | "A" ... "Z" .
     infinity = [ sign ] ( "inf" | "Inf" ) .

The base argument must be 0, 2, 10, or 16. Providing an invalid base argument will lead to a run-time panic.

For base 0, the number prefix determines the actual base: A prefix of "0x" or "0X" selects base 16, and a "0b" or "0B" prefix selects base 2; otherwise, the actual base is 10 and no prefix is accepted. The octal prefix "0" is not supported (a leading "0" is simply considered a "0").

A "p" exponent indicates a binary (rather then decimal) exponent; for instance "0x1.fffffffffffffp1023" (using base 0) represents the maximum float64 value. For hexadecimal mantissae, the exponent must be binary, if present (an "e" or "E" exponent indicator cannot be distinguished from a mantissa digit).

The returned *Float f is nil and the value of z is valid but not defined if an error is reported.

Parse is referenced in 8 repositories

github.com/golang/go github.com/hprose/hprose-golang github.com/go-edn/edn

...