Skip to content

Commit

Permalink
std/conv: fix FmtFloat returns old-style formats for the NaN, Inf, an…
Browse files Browse the repository at this point in the history
…d -Inf values
  • Loading branch information
mertcandav committed Feb 23, 2025
1 parent d7bac4e commit a65c6ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions std/conv/atof.jule
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn commonPrefixLenIgnoreCase(s: str, prefix: str): int {
}

// Returns the floating-point value for the special,
// possibly signed floating-point representations inf, infinity,
// possibly signed floating-point representations Inf, infinity,
// and NaN. The result is ok if a prefix of s contains one
// of these representations and n is the length of that prefix.
// The character case is ignored.
Expand Down Expand Up @@ -412,7 +412,7 @@ impl decimal {
goto out

overflow:
// ±inf
// ±Inf
mant = 0
exp = int(uint(1)<<flt.expbits - 1 + uint(flt.bias))
overflow = true
Expand Down Expand Up @@ -549,7 +549,7 @@ fn atof32exact(mantissa: u64, mut exp: int, mut neg: bool): (f: f32, ok: bool) {
}

// Converts the hex floating-point string s
// to a rounded f32 or f64 value (depending on flt==&f32_info or flt==&f64_info)
// to a rounded f32 or f64 value (depending on flt==&f32info or flt==&f64info)
// and returns it as a f64.
// The string s has already been parsed into a mantissa, exponent, and sign (neg==true for negative).
// If trunc is true, trailing non-zero bits have been omitted from the mantissa.
Expand Down Expand Up @@ -765,7 +765,7 @@ fn parseFloatPrefix(&s: str, bitSize: int): (f64, int, int) {
// away from the largest floating point number of the given size,
// Exceptional = Error.OutOfRange.
//
// Recognizes the string "NaN", and the (possibly signed) strings "inf" and "infinity"
// Recognizes the string "NaN", and the (possibly signed) strings "Inf" and "Infinity"
// as their respective special floating point values. It ignores case when matching.
fn ParseFloat(s: str, bitSize: int)!: f64 {
f, n, err := parseFloatPrefix(s, bitSize)
Expand Down
4 changes: 2 additions & 2 deletions std/conv/eisel_lemire.jule
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn eiselLemire64(mut man: u64, exp10: int, neg: bool): (f: f64, ok: bool) {
retExp2 += 1
}
// ret_exp2 is a u64. Zero or underflow means that we're in subnormal
// f64 space. 0x7FF or above means that we're in inf/NaN f64 space.
// f64 space. 0x7FF or above means that we're in Inf/NaN f64 space.
//
// The if block is equivalent to (but has fewer branches than):
// if retExp2 <= 0 || retExp2 >= 0x7FF { etc }
Expand Down Expand Up @@ -168,7 +168,7 @@ fn eiselLemire32(mut man: u64, exp10: int, neg: bool): (f: f32, ok: bool) {
retExp2 += 1
}
// retExp2 is a u64. Zero or underflow means that we're in subnormal
// f32 space. 0xFF or above means that we're in inf/NaN f32 space.
// f32 space. 0xFF or above means that we're in Inf/NaN f32 space.
//
// The if block is equivalent to (but has fewer branches than):
// if retExp2 <= 0 || retExp2 >= 0xFF { etc }
Expand Down
8 changes: 4 additions & 4 deletions std/conv/ftoa.jule
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ fn genericFtoa(mut dst: []byte, val: f64, fmt: byte, mut prec: int, bitSize: int

match exp {
| int(1<<flt.expbits - 1):
// +inf, NaN
// +Inf, NaN
match {
| mant != 0:
ret append(dst, "nan"...)
ret append(dst, "NaN"...)
| neg:
ret append(dst, "-inf"...)
ret append(dst, "-Inf"...)
|:
ret append(dst, "+inf"...)
ret append(dst, "+Inf"...)
}
| 0:
// denormalized
Expand Down

0 comments on commit a65c6ec

Please sign in to comment.