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

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Macros | Functions
long.h File Reference

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.

## Macros
#define | FIX2LONG RB_FIX2LONG
#define | FIX2ULONG RB_FIX2ULONG
#define | INT2FIX RB_INT2FIX
#define | LONG2FIX RB_INT2FIX
#define | LONG2NUM RB_LONG2NUM
#define | NUM2LONG RB_NUM2LONG
#define | NUM2ULONG RB_NUM2ULONG
#define | RB_FIX2LONG rb_fix2long
#define | RB_FIX2ULONG rb_fix2ulong
#define | RB_LONG2FIX RB_INT2FIX
#define | RB_LONG2NUM rb_long2num_inline
#define | RB_NUM2LONG rb_num2long_inline
#define | RB_NUM2ULONG rb_num2ulong_inline
#define | RB_ULONG2NUM rb_ulong2num_inline
#define | ULONG2NUM RB_ULONG2NUM
#define | rb_fix_new RB_INT2FIX
#define | rb_long2int rb_long2int_inline

## Functions
void | rb_out_of_int (SIGNED_VALUE num)
long | rb_num2long (VALUE num)
unsigned long | rb_num2ulong (VALUE num)

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

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.

### Q&A

- Q: Why are INT2FIX etc. here, not in `int.h`?
- A: Because they are in fact handling `long`. It seems someone did not understand the difference of `int` and `long` when they designed those macros.

Definition in file long.h.

## Macro Definition Documentation

## ◆ FIX2LONG

#define FIX2LONG RB_FIX2LONG

Definition at line 46 of file long.h.

## ◆ FIX2ULONG

#define FIX2ULONG RB_FIX2ULONG

Definition at line 47 of file long.h.

## ◆ INT2FIX

#define INT2FIX RB_INT2FIX

Definition at line 48 of file long.h.

## ◆ LONG2FIX

#define LONG2FIX RB_INT2FIX

Definition at line 49 of file long.h.

## ◆ LONG2NUM

#define LONG2NUM RB_LONG2NUM

Definition at line 50 of file long.h.

## ◆ NUM2LONG

#define NUM2LONG RB_NUM2LONG

Definition at line 51 of file long.h.

## ◆ NUM2ULONG

#define NUM2ULONG RB_NUM2ULONG

Definition at line 52 of file long.h.

## ◆ RB_FIX2LONG

#define RB_FIX2LONG rb_fix2long

Definition at line 53 of file long.h.

## ◆ RB_FIX2ULONG

#define RB_FIX2ULONG rb_fix2ulong

Definition at line 54 of file long.h.

## ◆ rb_fix_new

#define rb_fix_new RB_INT2FIX

Definition at line 61 of file long.h.

## ◆ RB_LONG2FIX

#define RB_LONG2FIX RB_INT2FIX

Definition at line 55 of file long.h.

## ◆ rb_long2int

#define rb_long2int rb_long2int_inline

Definition at line 62 of file long.h.

## ◆ RB_LONG2NUM

#define RB_LONG2NUM rb_long2num_inline

Definition at line 56 of file long.h.

## ◆ RB_NUM2LONG

#define RB_NUM2LONG rb_num2long_inline

Definition at line 57 of file long.h.

## ◆ RB_NUM2ULONG

#define RB_NUM2ULONG rb_num2ulong_inline

Definition at line 58 of file long.h.

## ◆ RB_ULONG2NUM

#define RB_ULONG2NUM rb_ulong2num_inline

Definition at line 59 of file long.h.

## ◆ ULONG2NUM

#define ULONG2NUM RB_ULONG2NUM

Definition at line 60 of file long.h.

## Function Documentation

## ◆ rb_num2long()

long rb_num2long | ( | VALUE | num | ) |

Definition at line 2894 of file numeric.c.

References FIX2LONG, FIXNUM_P, FLOAT_OUT_OF_RANGE, LONG_MAX_PLUS_ONE, LONG_MIN_MINUS_ONE_IS_LESS_THAN, NIL_P, rb_big2long(), rb_eTypeError, rb_raise(), rb_to_int(), RFLOAT_VALUE, T_BIGNUM, and T_FLOAT.

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

## ◆ rb_num2ulong()

unsigned long rb_num2ulong | ( | VALUE | num | ) |

Definition at line 2963 of file numeric.c.

References NULL.

Referenced by rb_num2uint().

## ◆ rb_out_of_int()

void rb_out_of_int | ( | SIGNED_VALUE | num | ) |

Definition at line 2969 of file numeric.c.

References num, PRIdVALUE, rb_eRangeError, and rb_raise().