Ruby: include/ruby/internal/arithmetic/int.h File Reference

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

Macros | Functions
int.h File Reference

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"`

Go to the source code of this file.

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

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

## 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

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

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.

Referenced by rb_fiber_scheduler_io_result(), rb_fiber_scheduler_process_wait(), rb_io_maybe_wait_readable(), rb_io_maybe_wait_writable(), rb_io_read_check(), and rb_io_wait().

## ◆ RB_NUM2INT

#define RB_NUM2INT rb_num2int_inline

Just another name of rb_num2int_inline.

Definition at line 38 of file int.h.

Referenced by rb_fiber_scheduler_io_result_apply(), rb_io_descriptor(), rb_io_maybe_wait_readable(), rb_io_maybe_wait_writable(), rb_io_wait(), and rb_num2char_inline().

## ◆ RB_UINT2NUM

#define RB_UINT2NUM rb_uint2num_inline

Just another name of rb_uint2num_inline.

Definition at line 39 of file int.h.

Referenced by rb_fiber_scheduler_io_wait_readable(), and rb_fiber_scheduler_io_wait_writable().

## Function Documentation

## ◆ RB_FIX2INT()

static int RB_FIX2INT | ( | VALUE | x | ) |
| inlinestatic

Converts a Fixnum into C's `int`.

Parameters

  [in] | x | Some 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_fix2int()

long rb_fix2int | ( | VALUE | num | ) |

Identical to rb_num2int().

Parameters

  [in] | num | Something numeric.

Exceptions

  rb_eTypeError | `num` is not a numeric.
  rb_eRangeError | `num` is out of range of `int`.

Returns
  The passed value converted into C's `long`.

Definition at line 3290 of file numeric.c.

Referenced by RB_FIX2INT(), rb_fix2int(), and rb_num2int_inline().

## ◆ RB_FIX2UINT()

static unsigned int RB_FIX2UINT | ( | VALUE | x | ) |
| inlinestatic

Converts a Fixnum into C's `int`.

Parameters

  [in] | x | Some 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_fix2uint()

unsigned long rb_fix2uint | ( | VALUE | num | ) |

Identical to rb_num2uint().

Parameters

  [in] | num | Something numeric.

Exceptions

  rb_eTypeError | `num` is not a numeric.
  rb_eRangeError | `num` is out of range of `unsigned int`.

Returns
  The passed value converted into C's `unsigned long`.

Definition at line 3302 of file numeric.c.

Referenced by RB_FIX2UINT(), and rb_fix2uint().

## ◆ rb_int2num_inline()

static VALUE rb_int2num_inline | ( | int | v | ) |
| inlinestatic

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

Parameters

  [in] | v | Arbitrary `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] | num | Something numeric.

Exceptions

  rb_eTypeError | `num` is not a numeric.
  rb_eRangeError | `num` is out of range of `int`.

Returns
  The passed value converted into C's `long`.

Definition at line 3284 of file numeric.c.

Referenced by rb_num2int(), and 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] | x | Something numeric.

Exceptions

  rb_eTypeError | `x` is not a numeric.
  rb_eRangeError | `x` 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()

static unsigned int RB_NUM2UINT | ( | VALUE | x | ) |
| inlinestatic

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

Parameters

  [in] | x | Something numeric.

Exceptions

  rb_eTypeError | `x` is not a numeric.
  rb_eRangeError | `x` 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_num2uint()

unsigned long rb_num2uint | ( | VALUE | num | ) |

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

Parameters

  [in] | num | Something numeric.

Exceptions

  rb_eTypeError | `num` is not a numeric.
  rb_eRangeError | `num` is out of range of `unsigned int`.

Returns
  The passed value converted into C's `unsigned long`.

Definition at line 3296 of file numeric.c.

Referenced by RB_NUM2UINT(), and rb_num2uint().

## ◆ 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] | v | Arbitrary `unsigned int` value.

Returns
  An instance of rb_cInteger.

Definition at line 254 of file int.h.