Skip to main content

oxilean_runtime/object/
rtobject_small_nat_group.rs

1//! # RtObject - small_nat_group Methods
2//!
3//! This module contains method implementations for `RtObject`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use super::functions::{MAX_SMALL_NAT, TAG_SMALL_NAT};
8use super::rtobject_type::RtObject;
9
10impl RtObject {
11    /// Create a small natural number (inline).
12    ///
13    /// Returns `None` if the value exceeds 56 bits.
14    pub fn small_nat(n: u64) -> Option<Self> {
15        if n > MAX_SMALL_NAT {
16            return None;
17        }
18        Some(RtObject {
19            bits: ((TAG_SMALL_NAT as u64) << 56) | n,
20        })
21    }
22    /// Create a natural number, using small representation if possible.
23    pub fn nat(n: u64) -> Self {
24        RtObject::small_nat(n).unwrap_or_else(|| RtObject::big_nat(n))
25    }
26}