From e95469e1c5458ece36d19c09dbfc20c7cdf770ff Mon Sep 17 00:00:00 2001 From: ChJR Date: Tue, 10 Nov 2020 01:32:54 +0900 Subject: [PATCH] Refine names for shorter code --- common/src/float_ops.rs | 16 ++++++++-------- vm/src/cformat.rs | 6 +++--- vm/src/format.rs | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/src/float_ops.rs b/common/src/float_ops.rs index 034b9dbf9..ab3c599fc 100644 --- a/common/src/float_ops.rs +++ b/common/src/float_ops.rs @@ -84,24 +84,24 @@ pub fn is_integer(v: f64) -> bool { } #[derive(Debug)] -pub enum FloatFormatCase { +pub enum Case { Lower, Upper, } -fn format_nan(case: FloatFormatCase) -> String { +fn format_nan(case: Case) -> String { let nan = match case { - FloatFormatCase::Lower => "nan", - FloatFormatCase::Upper => "NAN", + Case::Lower => "nan", + Case::Upper => "NAN", }; nan.to_string() } -fn format_inf(case: FloatFormatCase) -> String { +fn format_inf(case: Case) -> String { let inf = match case { - FloatFormatCase::Lower => "inf", - FloatFormatCase::Upper => "INF", + Case::Lower => "inf", + Case::Upper => "INF", }; inf.to_string() @@ -109,7 +109,7 @@ fn format_inf(case: FloatFormatCase) -> String { // Formats floats into Python style exponent notation, by first formatting in Rust style // exponent notation (`1.0000e0`), then convert to Python style (`1.0000e+00`). -pub fn format_float_as_exponent(precision: usize, magnitude: f64, case: FloatFormatCase) -> String { +pub fn format_exponent(precision: usize, magnitude: f64, case: Case) -> String { match magnitude { magnitude if magnitude.is_finite() => { let r_exp = format!("{:.*e}", precision, magnitude); diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index 1b634f654..396b2257e 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -329,11 +329,11 @@ impl CFormatSpec { } CFormatType::Float(CFloatType::Exponent(case)) => { let case = match case { - CFormatCase::Lowercase => float_ops::FloatFormatCase::Lower, - CFormatCase::Uppercase => float_ops::FloatFormatCase::Upper, + CFormatCase::Lowercase => float_ops::Case::Lower, + CFormatCase::Uppercase => float_ops::Case::Upper, }; let magnitude = num.abs(); - float_ops::format_float_as_exponent(precision, magnitude, case) + float_ops::format_exponent(precision, magnitude, case) } CFormatType::Float(CFloatType::General(case)) => { let precision = if precision == 0 { 1 } else { precision }; diff --git a/vm/src/format.rs b/vm/src/format.rs index 3d58b5e26..af552593d 100644 --- a/vm/src/format.rs +++ b/vm/src/format.rs @@ -375,15 +375,15 @@ impl FormatSpec { Some(FormatType::GeneralFormatLower) => { Err("Format code 'g' for object of type 'float' not implemented yet") } - Some(FormatType::ExponentUpper) => Ok(float_ops::format_float_as_exponent( + Some(FormatType::ExponentUpper) => Ok(float_ops::format_exponent( precision, magnitude, - float_ops::FloatFormatCase::Upper, + float_ops::Case::Upper, )), - Some(FormatType::ExponentLower) => Ok(float_ops::format_float_as_exponent( + Some(FormatType::ExponentLower) => Ok(float_ops::format_exponent( precision, magnitude, - float_ops::FloatFormatCase::Lower, + float_ops::Case::Lower, )), Some(FormatType::Percentage) => match magnitude { magnitude if magnitude.is_nan() => Ok("nan%".to_owned()),