Skip to content

Commit 2ffb26d

Browse files
author
Grahame Bowland
committed
---
yaml --- r: 15477 b: refs/heads/try c: 6b5731e h: refs/heads/master i: 15475: 95b6b95 v: v3
1 parent 7bfeb78 commit 2ffb26d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 658b6a741b7d2bd01c7e14211b4299f12c0a3ebf
5+
refs/heads/try: 6b5731e7045ce5ea3209f957d5275a765f883f26
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/libcore/float.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ This function accepts strings such as
110110
* '', or, equivalently, '.' (understood as 0)
111111
* '5.'
112112
* '.5', or, equivalently, '0.5'
113+
* 'inf', '-inf', 'NaN'
113114
114115
Leading and trailing whitespace are ignored.
115116
@@ -123,6 +124,14 @@ Leading and trailing whitespace are ignored.
123124
where `n` is the floating-point number represented by `[num]`.
124125
"]
125126
fn from_str(num: str) -> option<float> {
127+
if num == "inf" {
128+
ret some(infinity);
129+
} else if num == "-inf" {
130+
ret some(neg_infinity);
131+
} else if num == "NaN" {
132+
ret some(NaN);
133+
}
134+
126135
let mut pos = 0u; //Current byte position in the string.
127136
//Used to walk the string in O(n).
128137
let len = str::len(num); //Length of the string, in bytes.
@@ -301,6 +310,15 @@ fn test_from_str() {
301310
assert from_str("-.5") == some(-0.5);
302311
assert from_str("-.5") == some(-0.5);
303312
assert from_str("-5") == some(-5.);
313+
assert from_str("-0") == some(-0.);
314+
assert from_str("0") == some(0.);
315+
assert from_str("inf") == some(infinity);
316+
assert from_str("-inf") == some(neg_infinity);
317+
// note: NaN != NaN, hence this slightly complex test
318+
alt from_str("NaN") {
319+
some(f) { assert is_NaN(f); }
320+
none { fail; }
321+
}
304322

305323
assert from_str("") == none;
306324
assert from_str("x") == none;

0 commit comments

Comments
 (0)