Ruby
3.4.0dev (2024-11-05 revision 348a53415339076afc4a02fcd09f3ae36e9c4c61)
|
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"
Go to the source code of this file.
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... | |
Arithmetic conversion between C's long
and Ruby's.
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. __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.int.h
?long
. It seems someone did not understand the difference of int
and long
when they designed those macros. Definition in file long.h.
#define RB_FIX2LONG rb_fix2long |
Just another name of rb_fix2long.
#define RB_FIX2ULONG rb_fix2ulong |
Just another name of rb_fix2ulong.
#define rb_fix_new RB_INT2FIX |
Just another name of RB_INT2FIX.
#define RB_LONG2FIX RB_INT2FIX |
Just another name of RB_INT2FIX.
#define rb_long2int rb_long2int_inline |
Just another name of rb_long2int_inline.
#define RB_LONG2NUM rb_long2num_inline |
Just another name of rb_long2num_inline.
#define RB_NUM2LONG rb_num2long_inline |
Just another name of rb_num2long_inline.
#define RB_NUM2ULONG rb_num2ulong_inline |
Just another name of rb_num2ulong_inline.
#define RB_ULONG2NUM rb_ulong2num_inline |
Just another name of rb_ulong2num_inline.
|
inlinestatic |
Converts a Fixnum into C's long
.
[in] | x | Some Fixnum. |
long
. Definition at line 231 of file long.h.
Referenced by rb_fix2ulong().
|
inlinestatic |
|
inlinestatic |
Converts a C's long
into an instance of rb_cInteger.
[in] | i | Arbitrary long value. |
Definition at line 111 of file long.h.
Referenced by RB_CHR2FIX(), and rb_int2num_inline().
|
inlinestatic |
|
inlinestatic |
Converts a C's long
into an instance of rb_cInteger.
[in] | v | Arbitrary long value. |
long rb_num2long | ( | VALUE | num | ) |
Converts an instance of rb_cNumeric into C's long
.
[in] | num | Something numeric. |
rb_eTypeError | num is not a numeric. |
rb_eRangeError | num is out of range of long . |
long
. Definition at line 3196 of file numeric.c.
Referenced by rb_fix2short(), rb_num2fix(), rb_num2int(), rb_num2long_inline(), and rb_num2short().
|
inlinestatic |
Converts an instance of rb_cNumeric into C's long
.
[in] | x | Something numeric. |
rb_eTypeError | x is not a numeric. |
rb_eRangeError | x is out of range of long . |
long
. unsigned long rb_num2ulong | ( | VALUE | num | ) |
Converts an instance of rb_cNumeric into C's unsigned long
.
[in] | num | Something numeric. |
rb_eTypeError | num is not a numeric. |
rb_eRangeError | num is out of range of unsigned long . |
unsigned long
. Definition at line 3265 of file numeric.c.
Referenced by rb_num2uint(), and rb_num2ulong_inline().
|
inlinestatic |
Converts an instance of rb_cNumeric into C's unsigned long
.
[in] | x | Something numeric. |
rb_eTypeError | x is not a numeric. |
rb_eRangeError | x is out of range of unsigned long . |
unsigned long
. void rb_out_of_int | ( | SIGNED_VALUE | num | ) |
This is an utility function to raise an rb_eRangeError.
[in] | num | A signed value about to overflow. |
rb_eRangeError | num is out of range of int . |
Definition at line 3271 of file numeric.c.
Referenced by rb_long2int_inline().
|
inlinestatic |
Converts a C's unsigned long
into an instance of rb_cInteger.
[in] | v | Arbitrary unsigned long value. |