Skip to content

Commit e95469e

Browse files
committed
Refine names for shorter code
1 parent fdeb817 commit e95469e

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

common/src/float_ops.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,32 @@ pub fn is_integer(v: f64) -> bool {
8484
}
8585

8686
#[derive(Debug)]
87-
pub enum FloatFormatCase {
87+
pub enum Case {
8888
Lower,
8989
Upper,
9090
}
9191

92-
fn format_nan(case: FloatFormatCase) -> String {
92+
fn format_nan(case: Case) -> String {
9393
let nan = match case {
94-
FloatFormatCase::Lower => "nan",
95-
FloatFormatCase::Upper => "NAN",
94+
Case::Lower => "nan",
95+
Case::Upper => "NAN",
9696
};
9797

9898
nan.to_string()
9999
}
100100

101-
fn format_inf(case: FloatFormatCase) -> String {
101+
fn format_inf(case: Case) -> String {
102102
let inf = match case {
103-
FloatFormatCase::Lower => "inf",
104-
FloatFormatCase::Upper => "INF",
103+
Case::Lower => "inf",
104+
Case::Upper => "INF",
105105
};
106106

107107
inf.to_string()
108108
}
109109

110110
// Formats floats into Python style exponent notation, by first formatting in Rust style
111111
// exponent notation (`1.0000e0`), then convert to Python style (`1.0000e+00`).
112-
pub fn format_float_as_exponent(precision: usize, magnitude: f64, case: FloatFormatCase) -> String {
112+
pub fn format_exponent(precision: usize, magnitude: f64, case: Case) -> String {
113113
match magnitude {
114114
magnitude if magnitude.is_finite() => {
115115
let r_exp = format!("{:.*e}", precision, magnitude);

vm/src/cformat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,11 @@ impl CFormatSpec {
329329
}
330330
CFormatType::Float(CFloatType::Exponent(case)) => {
331331
let case = match case {
332-
CFormatCase::Lowercase => float_ops::FloatFormatCase::Lower,
333-
CFormatCase::Uppercase => float_ops::FloatFormatCase::Upper,
332+
CFormatCase::Lowercase => float_ops::Case::Lower,
333+
CFormatCase::Uppercase => float_ops::Case::Upper,
334334
};
335335
let magnitude = num.abs();
336-
float_ops::format_float_as_exponent(precision, magnitude, case)
336+
float_ops::format_exponent(precision, magnitude, case)
337337
}
338338
CFormatType::Float(CFloatType::General(case)) => {
339339
let precision = if precision == 0 { 1 } else { precision };

vm/src/format.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,15 @@ impl FormatSpec {
375375
Some(FormatType::GeneralFormatLower) => {
376376
Err("Format code 'g' for object of type 'float' not implemented yet")
377377
}
378-
Some(FormatType::ExponentUpper) => Ok(float_ops::format_float_as_exponent(
378+
Some(FormatType::ExponentUpper) => Ok(float_ops::format_exponent(
379379
precision,
380380
magnitude,
381-
float_ops::FloatFormatCase::Upper,
381+
float_ops::Case::Upper,
382382
)),
383-
Some(FormatType::ExponentLower) => Ok(float_ops::format_float_as_exponent(
383+
Some(FormatType::ExponentLower) => Ok(float_ops::format_exponent(
384384
precision,
385385
magnitude,
386-
float_ops::FloatFormatCase::Lower,
386+
float_ops::Case::Lower,
387387
)),
388388
Some(FormatType::Percentage) => match magnitude {
389389
magnitude if magnitude.is_nan() => Ok("nan%".to_owned()),

0 commit comments

Comments
 (0)