artichoke_backend/extn/core/float/
mruby.rs1use std::ffi::CStr;
2
3use crate::extn::core::float::Float;
4use crate::extn::prelude::*;
5
6const FLOAT_CSTR: &CStr = c"Float";
7static FLOAT_RUBY_SOURCE: &[u8] = include_bytes!("float.rb");
8
9pub fn init(interp: &mut Artichoke) -> InitializeResult<()> {
10 if interp.is_class_defined::<Float>() {
11 return Ok(());
12 }
13
14 let spec = class::Spec::new("Float", FLOAT_CSTR, None, None)?;
15 interp.def_class::<Float>(spec)?;
16 interp.eval(FLOAT_RUBY_SOURCE)?;
17
18 let dig = interp.convert(Float::DIG);
19 interp.define_class_constant::<Float>("DIG", dig)?;
20 let epsilon = interp.convert_mut(Float::EPSILON);
21 interp.define_class_constant::<Float>("EPSILON", epsilon)?;
22 let infinity = interp.convert_mut(Float::INFINITY);
23 interp.define_class_constant::<Float>("INFINITY", infinity)?;
24 let mant_dig = interp.convert(Float::MANT_DIG);
25 interp.define_class_constant::<Float>("MANT_DIG", mant_dig)?;
26 let max = interp.convert_mut(Float::MAX);
27 interp.define_class_constant::<Float>("MAX", max)?;
28 let max_10_exp = interp.convert(Float::MAX_10_EXP);
29 interp.define_class_constant::<Float>("MAX_10_EXP", max_10_exp)?;
30 let max_exp = interp.convert(Float::MAX_EXP);
31 interp.define_class_constant::<Float>("MAX_EXP", max_exp)?;
32 let min = interp.convert_mut(Float::MIN);
33 interp.define_class_constant::<Float>("MIN", min)?;
34 let min_10_exp = interp.convert(Float::MIN_10_EXP);
35 interp.define_class_constant::<Float>("MIN_10_EXP", min_10_exp)?;
36 let min_exp = interp.convert(Float::MIN_EXP);
37 interp.define_class_constant::<Float>("MIN_EXP", min_exp)?;
38 let nan = interp.convert_mut(Float::NAN);
39 interp.define_class_constant::<Float>("NAN", nan)?;
40 let radix = interp.convert(Float::RADIX);
41 interp.define_class_constant::<Float>("RADIX", radix)?;
42 let rounds = interp.convert(Float::ROUNDS);
43 interp.define_class_constant::<Float>("ROUNDS", rounds)?;
44
45 Ok(())
46}