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

(37a72b0150ec36b4ea27175039afc28c62207b0c)

Arithmetic conversion between C's long 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/assume.h"
#include "ruby/internal/attr/artificial.h"
#include "ruby/internal/attr/cold.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/special_consts.h"
#include "ruby/internal/value.h"
#include "ruby/assert.h"
Include dependency graph for long.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FIX2LONG   RB_FIX2LONG
 Old name of RB_FIX2LONG. More...
 
#define FIX2ULONG   RB_FIX2ULONG
 Old name of RB_FIX2ULONG. More...
 
#define INT2FIX   RB_INT2FIX
 Old name of RB_INT2FIX. More...
 
#define LONG2FIX   RB_INT2FIX
 Old name of RB_INT2FIX. More...
 
#define LONG2NUM   RB_LONG2NUM
 Old name of RB_LONG2NUM. More...
 
#define NUM2LONG   RB_NUM2LONG
 Old name of RB_NUM2LONG. More...
 
#define NUM2ULONG   RB_NUM2ULONG
 Old name of RB_NUM2ULONG. More...
 
#define RB_FIX2LONG   rb_fix2long
 Just another name of rb_fix2long. More...
 
#define RB_FIX2ULONG   rb_fix2ulong
 Just another name of rb_fix2ulong. More...
 
#define RB_LONG2FIX   RB_INT2FIX
 Just another name of RB_INT2FIX. More...
 
#define RB_LONG2NUM   rb_long2num_inline
 Just another name of rb_long2num_inline. More...
 
#define RB_NUM2LONG   rb_num2long_inline
 Just another name of rb_num2long_inline. More...
 
#define RB_NUM2ULONG   rb_num2ulong_inline
 Just another name of rb_num2ulong_inline. More...
 
#define RB_ULONG2NUM   rb_ulong2num_inline
 Just another name of rb_ulong2num_inline. More...
 
#define ULONG2NUM   RB_ULONG2NUM
 Old name of RB_ULONG2NUM. More...
 
#define rb_fix_new   RB_INT2FIX
 Just another name of RB_INT2FIX. More...
 
#define rb_long2int   rb_long2int_inline
 Just another name of rb_long2int_inline. More...
 

Functions

void rb_out_of_int (SIGNED_VALUE num)
 This is an utility function to raise an rb_eRangeError. More...
 
long rb_num2long (VALUE num)
 Converts an instance of rb_cNumeric into C's long. More...
 
unsigned long rb_num2ulong (VALUE num)
 Converts an instance of rb_cNumeric into C's unsigned long. More...
 
static VALUE RB_INT2FIX (long i)
 Converts a C's long into an instance of rb_cInteger. More...
 
static int rb_long2int_inline (long n)
 Checks if int can hold the given integer. More...
 
static long rb_fix2long (VALUE x)
 Converts a Fixnum into C's long. More...
 
static unsigned long rb_fix2ulong (VALUE x)
 Converts a Fixnum into C's unsigned long. More...
 
static long rb_num2long_inline (VALUE x)
 Converts an instance of rb_cNumeric into C's long. More...
 
static unsigned long rb_num2ulong_inline (VALUE x)
 Converts an instance of rb_cNumeric into C's unsigned long. More...
 
static VALUE rb_long2num_inline (long v)
 Converts a C's long into an instance of rb_cInteger. More...
 
static VALUE rb_ulong2num_inline (unsigned long v)
 Converts a C's unsigned long into an instance of rb_cInteger. More...
 

Detailed Description

Arithmetic conversion between C's long 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.

Q&A

Definition in file long.h.

Macro Definition Documentation

◆ RB_FIX2LONG

#define RB_FIX2LONG   rb_fix2long

Just another name of rb_fix2long.

Definition at line 53 of file long.h.

◆ RB_FIX2ULONG

#define RB_FIX2ULONG   rb_fix2ulong

Just another name of rb_fix2ulong.

Definition at line 54 of file long.h.

◆ rb_fix_new

#define rb_fix_new   RB_INT2FIX

Just another name of RB_INT2FIX.

Definition at line 61 of file long.h.

◆ RB_LONG2FIX

#define RB_LONG2FIX   RB_INT2FIX

Just another name of RB_INT2FIX.

Definition at line 55 of file long.h.

◆ rb_long2int

#define rb_long2int   rb_long2int_inline

Just another name of rb_long2int_inline.

Definition at line 62 of file long.h.

◆ RB_LONG2NUM

#define RB_LONG2NUM   rb_long2num_inline

Just another name of rb_long2num_inline.

Definition at line 56 of file long.h.

◆ RB_NUM2LONG

#define RB_NUM2LONG   rb_num2long_inline

Just another name of rb_num2long_inline.

Definition at line 57 of file long.h.

◆ RB_NUM2ULONG

#define RB_NUM2ULONG   rb_num2ulong_inline

Just another name of rb_num2ulong_inline.

Definition at line 58 of file long.h.

◆ RB_ULONG2NUM

#define RB_ULONG2NUM   rb_ulong2num_inline

Just another name of rb_ulong2num_inline.

Definition at line 59 of file long.h.

Function Documentation

◆ rb_fix2long()

static long rb_fix2long ( VALUE  x)
inlinestatic

Converts a Fixnum into C's long.

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

Definition at line 231 of file long.h.

Referenced by rb_fix2ulong().

◆ rb_fix2ulong()

static unsigned long rb_fix2ulong ( VALUE  x)
inlinestatic

Converts a Fixnum into C's unsigned long.

Parameters
[in]xSome Fixnum.
Precondition
Must not pass anything other than a Fixnum.
Returns
The passed value converted into C's unsigned long.
Note
Negative fixnums will be converted into large unsigned longs.

Definition at line 252 of file long.h.

◆ RB_INT2FIX()

static VALUE RB_INT2FIX ( long  i)
inlinestatic

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

Parameters
[in]iArbitrary long value.
Returns
An instance of rb_cInteger.

Definition at line 111 of file long.h.

Referenced by RB_CHR2FIX(), and rb_int2num_inline().

◆ rb_long2int_inline()

static int rb_long2int_inline ( long  n)
inlinestatic

Checks if int can hold the given integer.

Parameters
[in]nArbitrary long value.
Exceptions
rb_eRangeErrorn is out of range of int.
Returns
Identical value of type int

Definition at line 135 of file long.h.

◆ rb_long2num_inline()

static VALUE rb_long2num_inline ( long  v)
inlinestatic

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

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

Definition at line 308 of file long.h.

◆ rb_num2long()

long rb_num2long ( 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 long.
Returns
The passed value converted into C's long.

Definition at line 3196 of file numeric.c.

Referenced by rb_fix2short(), rb_num2fix(), rb_num2int(), rb_num2long_inline(), and rb_num2short().

◆ rb_num2long_inline()

static long rb_num2long_inline ( VALUE  x)
inlinestatic

Converts an instance of rb_cNumeric into C's long.

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

Definition at line 267 of file long.h.

◆ rb_num2ulong()

unsigned long rb_num2ulong ( 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 long.
Returns
The passed value converted into C's unsigned long.

Definition at line 3265 of file numeric.c.

Referenced by rb_num2uint(), and rb_num2ulong_inline().

◆ rb_num2ulong_inline()

static unsigned long rb_num2ulong_inline ( VALUE  x)
inlinestatic

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

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

Definition at line 293 of file long.h.

◆ rb_out_of_int()

void rb_out_of_int ( SIGNED_VALUE  num)

This is an utility function to raise an rb_eRangeError.

Parameters
[in]numA signed value about to overflow.
Exceptions
rb_eRangeErrornum is out of range of int.

Definition at line 3271 of file numeric.c.

Referenced by rb_long2int_inline().

◆ rb_ulong2num_inline()

static VALUE rb_ulong2num_inline ( unsigned long  v)
inlinestatic

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

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

Definition at line 323 of file long.h.