2
2
pub mod with_rug;
3
3
4
4
#[ cfg( feature = "rug" ) ]
5
- use rug:: { Float , ops:: Pow } ;
5
+ use rug:: { ops:: Pow , Float } ;
6
6
7
7
#[ cfg( not( feature = "rug" ) ) ]
8
8
pub mod regular;
@@ -148,7 +148,8 @@ impl ScientificNotation {
148
148
value,
149
149
exponent : exponent - modulo + 1 ,
150
150
imaginary : self . imaginary ,
151
- } . to_string ( )
151
+ }
152
+ . to_string ( )
152
153
}
153
154
}
154
155
@@ -547,7 +548,7 @@ impl KalkValue {
547
548
let exponent = value. abs ( ) . log10 ( ) . floor ( ) as i32 + 1 ;
548
549
549
550
ScientificNotation {
550
- value : value / ( 10f64 . powf ( exponent as f64 - 1f64 ) as f64 ) ,
551
+ value : value / ( 10f64 . pow ( exponent - 1 ) ) ,
551
552
// I... am not sure what else to do...
552
553
exponent,
553
554
imaginary : complex_number_type == ComplexNumberType :: Imaginary ,
@@ -936,7 +937,7 @@ impl KalkValue {
936
937
) => {
937
938
if self . has_imaginary ( )
938
939
|| imaginary_rhs != & 0f64
939
- || ( real < 0f64 && real_rhs < & 1f64 )
940
+ || ( real_rhs > & 0f64 && real_rhs < & 1f64 )
940
941
{
941
942
let a = real;
942
943
let b = imaginary;
@@ -1155,6 +1156,10 @@ pub fn format_number(input: f64) -> String {
1155
1156
1156
1157
#[ cfg( feature = "rug" ) ]
1157
1158
pub fn format_number_big ( input : & Float ) -> String {
1159
+ if input. clone ( ) . log10 ( ) < 0f64 {
1160
+ return input. to_f64 ( ) . to_string ( ) ;
1161
+ }
1162
+
1158
1163
let input_str = input. to_string ( ) ;
1159
1164
let mut result = if input_str. contains ( '.' ) {
1160
1165
input_str
@@ -1562,6 +1567,7 @@ mod tests {
1562
1567
fn test_to_string_pretty ( ) {
1563
1568
let in_out = vec ! [
1564
1569
( float!( 0.99999 ) , float!( 0.0 ) , "0.99999 ≈ 1" ) ,
1570
+ ( float!( 0.00000001 ) , float!( 0.0 ) , "0.00000001 ≈ 10^-8" ) ,
1565
1571
( float!( -0.99999 ) , float!( 0.0 ) , "-0.99999 ≈ -1" ) ,
1566
1572
( float!( 0.0 ) , float!( 0.99999 ) , "0.99999i ≈ i" ) ,
1567
1573
( float!( 0.000000001 ) , float!( 0.0 ) , "10^-9 ≈ 0" ) ,
@@ -1601,7 +1607,8 @@ mod tests {
1601
1607
( float!( 3.00000000004 ) , float!( 0.0 ) , "3" ) ,
1602
1608
] ;
1603
1609
for ( real, imaginary, output) in in_out {
1604
- let result = KalkValue :: Number ( real, imaginary, None ) . to_string_pretty ( ScientificNotationFormat :: Normal ) ;
1610
+ let result = KalkValue :: Number ( real, imaginary, None )
1611
+ . to_string_pretty ( ScientificNotationFormat :: Normal ) ;
1605
1612
assert_eq ! ( output, result) ;
1606
1613
}
1607
1614
}
@@ -1624,7 +1631,10 @@ mod tests {
1624
1631
imaginary : false ,
1625
1632
} ;
1626
1633
1627
- assert_eq ! ( sci. to_string_format( ScientificNotationFormat :: Engineering ) , output) ;
1634
+ assert_eq ! (
1635
+ sci. to_string_format( ScientificNotationFormat :: Engineering ) ,
1636
+ output
1637
+ ) ;
1628
1638
}
1629
1639
}
1630
1640
}
0 commit comments