QuakeServer.TextNumbers (quake_server v0.1.0)

Copy Markdown View Source

Numbers read from text as C's strtod, strtol and atof read them, the readings FTE's stof builtin and its entity-key parser (ED_ParseEpair) use.

QuakeServer.TextNumbers.strtod(" .3 rest")
#=> {0.3, " rest"}
QuakeServer.TextNumbers.atof(".3")
#=> 0.30000001192092896
QuakeServer.TextNumbers.strtol("0x1f")
#=> {31, ""}

Leading white space (space, tab, newline, vertical tab, form feed, carriage return) is skipped and a + or - sign read. strtod reads a decimal number (digits with an optional point, at least one digit, an optional exponent e or E) or a hexadecimal one (0x or 0X, hex digits with an optional point, an optional binary exponent p or P); strtol reads base 0: 0x hexadecimal, a leading 0 octal, else decimal. Text with no number reads as 0 with the whole text left. Infinities and NaNs, which QuakeC memory cannot hold, are not read; a number beyond a double's range reads as the largest double of its sign.

Summary

Functions

The number at the front of text as atof reads it into a 32-bit float.

value rounded to a 32-bit float, a value beyond its range to its largest of that sign.

value wrapped to a signed 32-bit integer.

The number at the front of text, a double, and the text after it.

The whole number at the front of text, read in base 0, and the text after it.

Functions

atof(text)

@spec atof(String.t()) :: float()

The number at the front of text as atof reads it into a 32-bit float.

float32(value)

@spec float32(number()) :: float()

value rounded to a 32-bit float, a value beyond its range to its largest of that sign.

int32(value)

@spec int32(integer()) :: integer()

value wrapped to a signed 32-bit integer.

strtod(text)

@spec strtod(String.t()) :: {float(), String.t()}

The number at the front of text, a double, and the text after it.

strtol(text)

@spec strtol(String.t()) :: {integer(), String.t()}

The whole number at the front of text, read in base 0, and the text after it.