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

Method numeric

crates/stdlib/src/unicodedata.rs:293–312  ·  view source on GitHub ↗
(
            &self,
            character: PyStrRef,
            default: OptionalArg<PyObjectRef>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

291
292 #[pymethod]
293 fn numeric(
294 &self,
295 character: PyStrRef,
296 default: OptionalArg<PyObjectRef>,
297 vm: &VirtualMachine,
298 ) -> PyResult {
299 let ch = self.extract_char(character, vm)?.and_then(|c| c.to_char());
300 if let Some(ch) = ch {
301 match ch.numeric_value() {
302 Some(Number::Integer(n)) => {
303 return Ok(vm.ctx.new_float(n as f64).into());
304 }
305 Some(Number::Rational(num, den)) => {
306 return Ok(vm.ctx.new_float(num as f64 / den as f64).into());
307 }
308 None => {}
309 }
310 }
311 default.ok_or_else(|| vm.new_value_error("not a numeric character"))
312 }
313
314 #[pygetset]
315 fn unidata_version(&self) -> String {

Callers 4

test_numericMethod · 0.80

Calls 4

extract_charMethod · 0.80
ok_or_elseMethod · 0.80
to_charMethod · 0.45
new_floatMethod · 0.45

Tested by 4

test_numericMethod · 0.64