Ruby  3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
Macros | Functions
int.h File Reference

(37a72b0150ec36b4ea27175039afc28c62207b0c)

Arithmetic conversion between C's int and Ruby's. More...

#include "ruby/internal/config.h"
#include "ruby/internal/arithmetic/fixnum.h"
#include "ruby/internal/arithmetic/intptr_t.h"
#include "ruby/internal/arithmetic/long.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/compiler_is.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h"
#include "ruby/internal/value.h"
#include "ruby/internal/warning_push.h"
#include "ruby/assert.h"
Include dependency graph for int.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RB_INT2NUM   rb_int2num_inline
 Just another name of rb_int2num_inline. More...
 
#define RB_NUM2INT   rb_num2int_inline
 Just another name of rb_num2int_inline. More...
 
#define RB_UINT2NUM   rb_uint2num_inline
 Just another name of rb_uint2num_inline. More...
 
#define FIX2INT   RB_FIX2INT
 Old name of RB_FIX2INT. More...
 
#define FIX2UINT   RB_FIX2UINT
 Old name of RB_FIX2UINT. More...
 
#define INT2NUM   RB_INT2NUM
 Old name of RB_INT2NUM. More...
 
#define NUM2INT   RB_NUM2INT
 Old name of RB_NUM2INT. More...
 
#define NUM2UINT   RB_NUM2UINT
 Old name of RB_NUM2UINT. More...
 
#define UINT2NUM   RB_UINT2NUM
 Old name of RB_UINT2NUM. More...
 

Functions

long rb_num2int (VALUE num)
 Converts an instance of rb_cNumeric into C's long. More...
 
long rb_fix2int (VALUE num)
 Identical to rb_num2int(). More...
 
unsigned long rb_num2uint (VALUE num)
 Converts an instance of rb_cNumeric into C's unsigned long. More...
 
unsigned long rb_fix2uint (VALUE num)
 Identical to rb_num2uint(). More...
 
static int RB_FIX2INT (VALUE x)
 Converts a Fixnum into C's int. More...
 
static int rb_num2int_inline (VALUE x)
 Converts an instance of rb_cNumeric into C's int. More...
 
static unsigned int RB_NUM2UINT (VALUE x)
 Converts an instance of rb_cNumeric into C's unsigned int. More...
 
static unsigned int RB_FIX2UINT (VALUE x)
 Converts a Fixnum into C's int. More...
 
static VALUE rb_int2num_inline (int v)
 Converts a C's int into an instance of rb_cInteger. More...
 
static VALUE rb_uint2num_inline (unsigned int v)
 Converts a C's unsigned int into an instance of rb_cInteger. More...
 

Detailed Description

Arithmetic conversion between C's int and Ruby's.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file int.h.

Macro Definition Documentation

◆ RB_INT2NUM

#define RB_INT2NUM   rb_int2num_inline

Just another name of rb_int2num_inline.

Definition at line 37 of file int.h.

◆ RB_NUM2INT

#define RB_NUM2INT   rb_num2int_inline

Just another name of rb_num2int_inline.

Definition at line 38 of file int.h.

◆ RB_UINT2NUM

#define RB_UINT2NUM   rb_uint2num_inline

Just another name of rb_uint2num_inline.

Definition at line 39 of file int.h.

Function Documentation

◆ rb_fix2int()

long rb_fix2int ( VALUE  num)

Identical to rb_num2int().

Parameters
[in]numSomething numeric.
Exceptions
rb_eTypeErrornum is not a numeric.
rb_eRangeErrornum is out of range of int.
Returns
The passed value converted into C's long.

Definition at line 3350 of file numeric.c.

Referenced by RB_FIX2INT(), and rb_num2int_inline().

◆ RB_FIX2INT()

static int RB_FIX2INT ( VALUE  x)
inlinestatic

Converts a Fixnum into C's int.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into C's int.

Definition at line 129 of file int.h.

◆ rb_fix2uint()

unsigned long rb_fix2uint ( VALUE  num)

Identical to rb_num2uint().

Parameters
[in]numSomething numeric.
Exceptions
rb_eTypeErrornum is not a numeric.
rb_eRangeErrornum is out of range of unsigned int.
Returns
The passed value converted into C's unsigned long.

Definition at line 3362 of file numeric.c.

Referenced by RB_FIX2UINT().

◆ RB_FIX2UINT()

static unsigned int RB_FIX2UINT ( VALUE  x)
inlinestatic

Converts a Fixnum into C's int.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into C's int.

Definition at line 208 of file int.h.

◆ rb_int2num_inline()

static VALUE rb_int2num_inline ( int  v)
inlinestatic

Converts a C's int into an instance of rb_cInteger.

Parameters
[in]vArbitrary int value.
Returns
An instance of rb_cInteger.

Definition at line 239 of file int.h.

◆ rb_num2int()

long rb_num2int ( VALUE  num)

Converts an instance of rb_cNumeric into C's long.

Parameters
[in]numSomething numeric.
Exceptions
rb_eTypeErrornum is not a numeric.
rb_eRangeErrornum is out of range of int.
Returns
The passed value converted into C's long.

Definition at line 3344 of file numeric.c.

Referenced by rb_num2int_inline().

◆ rb_num2int_inline()

static int rb_num2int_inline ( VALUE  x)
inlinestatic

Converts an instance of rb_cNumeric into C's int.

Parameters
[in]xSomething numeric.
Exceptions
rb_eTypeErrorx is not a numeric.
rb_eRangeErrorx is out of range of int.
Returns
The passed value converted into C's int.

Definition at line 158 of file int.h.

◆ rb_num2uint()

unsigned long rb_num2uint ( VALUE  num)

Converts an instance of rb_cNumeric into C's unsigned long.

Parameters
[in]numSomething numeric.
Exceptions
rb_eTypeErrornum is not a numeric.
rb_eRangeErrornum is out of range of unsigned int.
Returns
The passed value converted into C's unsigned long.

Definition at line 3356 of file numeric.c.

Referenced by RB_NUM2UINT().

◆ RB_NUM2UINT()

static unsigned int RB_NUM2UINT ( VALUE  x)
inlinestatic

Converts an instance of rb_cNumeric into C's unsigned int.

Parameters
[in]xSomething numeric.
Exceptions
rb_eTypeErrorx is not a numeric.
rb_eRangeErrorx is out of range of unsigned int.
Returns
The passed value converted into C's unsigned int.

Definition at line 185 of file int.h.

◆ rb_uint2num_inline()

static VALUE rb_uint2num_inline ( unsigned int  v)
inlinestatic

Converts a C's unsigned int into an instance of rb_cInteger.

Parameters
[in]vArbitrary unsigned int value.
Returns
An instance of rb_cInteger.

Definition at line 254 of file int.h.