Skip to content

Commit fa5ca0d

Browse files
authored
Implement RBIGNUM_POSITIVE_P and RBIGNUM_NEGATIVE_P to check the sign of bignum objects (#542)
1 parent f3e6538 commit fa5ca0d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

crates/rb-sys/src/macros.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,31 @@ pub unsafe fn RTYPEDDATA_TYPE(obj: VALUE) -> *const rb_data_type_t {
341341
pub unsafe fn RTYPEDDATA_GET_DATA(obj: VALUE) -> *mut c_void {
342342
api().rtypeddata_get_data(obj)
343343
}
344+
345+
/// Checks if the bignum is positive.
346+
///
347+
/// @param[in] b An object of RBignum.
348+
/// @retval false `b` is less than zero.
349+
/// @retval true Otherwise.
350+
///
351+
/// # Safety
352+
/// This function is unsafe because it could dereference a raw pointer when
353+
/// accessing the underlying bignum structure.
354+
#[inline]
355+
pub unsafe fn RBIGNUM_POSITIVE_P(b: VALUE) -> bool {
356+
api().bignum_positive_p(b)
357+
}
358+
359+
/// Checks if the bignum is negative.
360+
///
361+
/// @param[in] b An object of RBignum.
362+
/// @retval true `b` is less than zero.
363+
/// @retval false Otherwise.
364+
///
365+
/// # Safety
366+
/// This function is unsafe because it could dereference a raw pointer when
367+
/// accessing the underlying bignum structure.
368+
#[inline]
369+
pub unsafe fn RBIGNUM_NEGATIVE_P(b: VALUE) -> bool {
370+
api().bignum_negative_p(b)
371+
}

0 commit comments

Comments
 (0)