mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Refine names for shorter code
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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()),
|
||||
|
||||
Reference in New Issue
Block a user