Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add INT2FIX, INT2NUM, FIX2LONG and NUM2LONG #406

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

ianks
Copy link
Collaborator

@ianks ianks commented Jul 29, 2024

This PR introduces several new integer conversion functions to the Stable API, enhancing the capabilities of the rb-sys crate for handling Ruby integer types.

Changes

  1. Added the following functions to the StableApiDefinition trait:

    • int2fix: Converts a C int to a Ruby Fixnum
    • int2num: Converts a C int to a Ruby Integer (Fixnum or Bignum)
    • fix2long: Converts a Ruby Fixnum to a C long
    • num2long: Converts a Ruby Integer (Fixnum or Bignum) to a C long
  2. Implemented these functions in both the pure Rust and compiled C versions of the Stable API.

  3. Added corresponding macros in macros.rs:

    • INT2FIX
    • INT2NUM
    • FIX2LONG
    • NUM2LONG

Impact

These additions will allow Rust developers using rb-sys to more easily work with Ruby's integer types, providing a safer and more idiomatic way to convert between Rust and Ruby number representations.

Testing

The PR includes extensive parity tests to ensure that the new functions behave identically to their Ruby counterparts across a wide range of input values, including edge cases like maximum and minimum Fixnum values.

@ianks ianks force-pushed the numeric-macros branch 3 times, most recently from e5997d2 to 6458a95 Compare July 29, 2024 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant