| ... | ... | @@ -240,14 +240,15 @@ pub fn parseNumber(comptime T: type, s: []const u8, negative: bool) ?Number(T) { |
| 240 | 240 | return null; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | | fn parsePartialInfOrNan(comptime T: type, s: []const u8, n: *usize) ?T { |
| 243 | fn parsePartialInfOrNan(comptime T: type, s: []const u8, negative: bool, n: *usize) ?T { |
| 244 | 244 | // inf/infinity; infxxx should only consume inf. |
| 245 | 245 | if (std.ascii.startsWithIgnoreCase(s, "inf")) { |
| 246 | 246 | n.* = 3; |
| 247 | 247 | if (std.ascii.startsWithIgnoreCase(s[3..], "inity")) { |
| 248 | 248 | n.* = 8; |
| 249 | 249 | } |
| 250 | | return std.math.inf(T); |
| 250 | |
| 251 | return if (!negative) std.math.inf(T) else -std.math.inf(T); |
| 251 | 252 | } |
| 252 | 253 | |
| 253 | 254 | if (std.ascii.startsWithIgnoreCase(s, "nan")) { |
| ... | ... | @@ -260,11 +261,8 @@ fn parsePartialInfOrNan(comptime T: type, s: []const u8, n: *usize) ?T { |
| 260 | 261 | |
| 261 | 262 | pub fn parseInfOrNan(comptime T: type, s: []const u8, negative: bool) ?T { |
| 262 | 263 | var consumed: usize = 0; |
| 263 | | if (parsePartialInfOrNan(T, s, &consumed)) |special| { |
| 264 | if (parsePartialInfOrNan(T, s, negative, &consumed)) |special| { |
| 264 | 265 | if (s.len == consumed) { |
| 265 | | if (negative) { |
| 266 | | return -1 * special; |
| 267 | | } |
| 268 | 266 | return special; |
| 269 | 267 | } |
| 270 | 268 | } |