about summary refs log tree commit diff
path: root/src/libcore/float.rs
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-10-11 14:12:50 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-10-11 14:17:59 -0700
commit5a8ba073bcd6ee6fd34ff545845a746cddc4904f (patch)
treeac61c449c7178937914d59a8c6c84bed74a52bd8 /src/libcore/float.rs
parent41bce91cb871ba90caf7d3e56243141dd3390bca (diff)
downloadrust-5a8ba073bcd6ee6fd34ff545845a746cddc4904f.tar.gz
rust-5a8ba073bcd6ee6fd34ff545845a746cddc4904f.zip
Make to_str pure and fix const parameters for str-mutating functions
Two separate changes that got intertwined (sorry):

Make to_str pure. Closes #3691

In str, change functions like push_char to take an &mut str instead of
an &str. Closes #3710
Diffstat (limited to 'src/libcore/float.rs')
-rw-r--r--src/libcore/float.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libcore/float.rs b/src/libcore/float.rs
index 098e82f5fad..dd46d30d6ba 100644
--- a/src/libcore/float.rs
+++ b/src/libcore/float.rs
@@ -91,7 +91,7 @@ pub mod consts {
  * * digits - The number of significant digits
  * * exact - Whether to enforce the exact number of significant digits
  */
-pub fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
+pub pure fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
     if is_NaN(num) { return ~"NaN"; }
     if num == infinity { return ~"inf"; }
     if num == neg_infinity { return ~"-inf"; }
@@ -125,7 +125,8 @@ pub fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
         // store the next digit
         frac *= 10.0;
         let digit = frac as uint;
-        fractionalParts.push(digit);
+        // Bleh: not really unsafe.
+        unsafe { fractionalParts.push(digit); }
 
         // calculate the next frac
         frac -= digit as float;
@@ -140,7 +141,8 @@ pub fn to_str_common(num: float, digits: uint, exact: bool) -> ~str {
     // turn digits into string
     // using stack of digits
     while fractionalParts.is_not_empty() {
-        let mut adjusted_digit = carry + fractionalParts.pop();
+        // Bleh; shouldn't need to be unsafe
+        let mut adjusted_digit = carry + unsafe { fractionalParts.pop() };
 
         if adjusted_digit == 10 {
             carry = 1;
@@ -196,7 +198,7 @@ pub fn test_to_str_exact_do_decimal() {
  * * num - The float value
  * * digits - The number of significant digits
  */
-pub fn to_str(num: float, digits: uint) -> ~str {
+pub pure fn to_str(num: float, digits: uint) -> ~str {
     to_str_common(num, digits, false)
 }
 
@@ -361,7 +363,7 @@ pub fn from_str(num: &str) -> Option<float> {
  *
  * `NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
  */
-pub fn pow_with_uint(base: uint, pow: uint) -> float {
+pub pure fn pow_with_uint(base: uint, pow: uint) -> float {
     if base == 0u {
         if pow == 0u {
             return NaN as float;