Skip to content

Commit ab71937

Browse files
Kimundibrson
authored andcommitted
---
yaml --- r: 42941 b: refs/heads/try c: eeb89c5 h: refs/heads/master i: 42939: 9495aae v: v3
1 parent 80840f7 commit ab71937

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: 974d5ac1e095379d63f546da7b8e9d61f7fdcc76
5+
refs/heads/try: eeb89c5012ef3e6a467835af67fed3ab8da3d84b
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libcore/num/f32.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,36 @@ pub pure fn to_str_hex(num: f32) -> ~str {
375375
*
376376
* * num - The float value
377377
* * radix - The base to use
378+
*
379+
* # Failure
380+
*
381+
* Fails if called on a special value like `inf`, `-inf` or `NaN` due to
382+
* possible misinterpretation of the result at higher bases. If those values
383+
* are expected, use `to_str_radix_special()` instead.
378384
*/
379385
#[inline(always)]
380386
pub pure fn to_str_radix(num: f32, rdx: uint) -> ~str {
381-
let (r, _) = num::to_str_common(
387+
let (r, special) = num::to_str_common(
382388
&num, rdx, true, true, num::SignNeg, num::DigAll);
389+
if special { die!(~"number has a special value, \
390+
try to_str_radix_special() if those are expected") }
383391
r
384392
}
385393

394+
/**
395+
* Converts a float to a string in a given radix, and a flag indicating
396+
* whether it's a special value
397+
*
398+
* # Arguments
399+
*
400+
* * num - The float value
401+
* * radix - The base to use
402+
*/
403+
#[inline(always)]
404+
pub pure fn to_str_radix_special(num: f32, rdx: uint) -> (~str, bool) {
405+
num::to_str_common(&num, rdx, true, true, num::SignNeg, num::DigAll)
406+
}
407+
386408
/**
387409
* Converts a float to a string with exactly the number of
388410
* provided significant digits

branches/try/src/libcore/num/f64.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,14 +399,36 @@ pub pure fn to_str_hex(num: f64) -> ~str {
399399
*
400400
* * num - The float value
401401
* * radix - The base to use
402+
*
403+
* # Failure
404+
*
405+
* Fails if called on a special value like `inf`, `-inf` or `NaN` due to
406+
* possible misinterpretation of the result at higher bases. If those values
407+
* are expected, use `to_str_radix_special()` instead.
402408
*/
403409
#[inline(always)]
404410
pub pure fn to_str_radix(num: f64, rdx: uint) -> ~str {
405-
let (r, _) = num::to_str_common(
411+
let (r, special) = num::to_str_common(
406412
&num, rdx, true, true, num::SignNeg, num::DigAll);
413+
if special { die!(~"number has a special value, \
414+
try to_str_radix_special() if those are expected") }
407415
r
408416
}
409417

418+
/**
419+
* Converts a float to a string in a given radix, and a flag indicating
420+
* whether it's a special value
421+
*
422+
* # Arguments
423+
*
424+
* * num - The float value
425+
* * radix - The base to use
426+
*/
427+
#[inline(always)]
428+
pub pure fn to_str_radix_special(num: f64, rdx: uint) -> (~str, bool) {
429+
num::to_str_common(&num, rdx, true, true, num::SignNeg, num::DigAll)
430+
}
431+
410432
/**
411433
* Converts a float to a string with exactly the number of
412434
* provided significant digits

branches/try/src/libcore/num/float.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,36 @@ pub pure fn to_str_hex(num: float) -> ~str {
136136
*
137137
* * num - The float value
138138
* * radix - The base to use
139+
*
140+
* # Failure
141+
*
142+
* Fails if called on a special value like `inf`, `-inf` or `NaN` due to
143+
* possible misinterpretation of the result at higher bases. If those values
144+
* are expected, use `to_str_radix_special()` instead.
139145
*/
140146
#[inline(always)]
141147
pub pure fn to_str_radix(num: float, radix: uint) -> ~str {
142-
let (r, _) = num::to_str_common(
148+
let (r, special) = num::to_str_common(
143149
&num, radix, true, true, num::SignNeg, num::DigAll);
150+
if special { die!(~"number has a special value, \
151+
try to_str_radix_special() if those are expected") }
144152
r
145153
}
146154
155+
/**
156+
* Converts a float to a string in a given radix, and a flag indicating
157+
* whether it's a special value
158+
*
159+
* # Arguments
160+
*
161+
* * num - The float value
162+
* * radix - The base to use
163+
*/
164+
#[inline(always)]
165+
pub pure fn to_str_radix_special(num: float, radix: uint) -> (~str, bool) {
166+
num::to_str_common(&num, radix, true, true, num::SignNeg, num::DigAll)
167+
}
168+
147169
/**
148170
* Converts a float to a string with exactly the number of
149171
* provided significant digits

0 commit comments

Comments
 (0)