MCPcopy Index your code
hub / github.com/RustPython/RustPython / float_repr

Function float_repr

crates/stdlib/src/math.rs:943–961  ·  view source on GitHub ↗

Format a float in Python style (ensures trailing .0 for integers).

(value: f64)

Source from the content-addressed store, hash-verified

941
942/// Format a float in Python style (ensures trailing .0 for integers).
943fn float_repr(value: f64) -> String {
944 if value.is_nan() {
945 "nan".to_owned()
946 } else if value.is_infinite() {
947 if value.is_sign_positive() {
948 "inf".to_owned()
949 } else {
950 "-inf".to_owned()
951 }
952 } else {
953 let s = format!("{}", value);
954 // If no decimal point and not in scientific notation, add .0
955 if !s.contains('.') && !s.contains('e') && !s.contains('E') {
956 format!("{}.0", s)
957 } else {
958 s
959 }
960 }
961}

Callers

nothing calls this directly

Calls 4

is_nanMethod · 0.45
to_ownedMethod · 0.45
is_infiniteMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected