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

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

Macros | Functions
short.h File Reference

Arithmetic conversion between C's `short` and Ruby's. More...

`#include "ruby/internal/value.h"`
`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/special_consts.h"`

Go to the source code of this file.

## Macros
#define | RB_NUM2SHORT rb_num2short_inline
| Just another name of rb_num2short_inline.
#define | RB_NUM2USHORT rb_num2ushort
| Just another name of rb_num2ushort.
#define | NUM2SHORT RB_NUM2SHORT
| Old name of RB_NUM2SHORT.
#define | NUM2USHORT RB_NUM2USHORT
| Old name of RB_NUM2USHORT.
#define | USHORT2NUM RB_INT2FIX
| Old name of RB_INT2FIX.
#define | RB_FIX2SHORT rb_fix2short
| Just another name of rb_fix2ushort.
#define | FIX2SHORT RB_FIX2SHORT
| Old name of RB_FIX2SHORT.

## Functions
short | rb_num2short (VALUE num)
| Converts an instance of rb_cNumeric into C's `short`.
unsigned short | rb_num2ushort (VALUE num)
| Converts an instance of rb_cNumeric into C's `unsigned short`.
short | rb_fix2short (VALUE num)
| Identical to rb_num2short().
unsigned short | rb_fix2ushort (VALUE num)
| Identical to rb_num2ushort().
static short | rb_num2short_inline (VALUE x)
| Identical to rb_num2short().

## Detailed Description

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

Shyouhei wonders: why there is no SHORT2NUM, given there are both USHORT2NUM and CHR2FIX?

Definition in file short.h.

## Macro Definition Documentation

## ◆ RB_FIX2SHORT

#define RB_FIX2SHORT rb_fix2short

Just another name of rb_fix2ushort.

Definition at line 35 of file short.h.

## ◆ RB_NUM2SHORT

#define RB_NUM2SHORT rb_num2short_inline

Just another name of rb_num2short_inline.

Definition at line 30 of file short.h.

## ◆ RB_NUM2USHORT

#define RB_NUM2USHORT rb_num2ushort

Just another name of rb_num2ushort.

Definition at line 31 of file short.h.

## Function Documentation

## ◆ rb_fix2short()

short rb_fix2short | ( | VALUE | num | ) |

Identical to rb_num2short().

Parameters

  [in] | num | Something numeric.

Exceptions

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

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

Definition at line 3349 of file numeric.c.

Referenced by rb_fix2short(), and rb_num2short_inline().

## ◆ rb_fix2ushort()

unsigned short rb_fix2ushort | ( | VALUE | num | ) |

Identical to rb_num2ushort().

Parameters

  [in] | num | Something numeric.

Exceptions

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

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

Definition at line 3368 of file numeric.c.

Referenced by rb_fix2ushort().

## ◆ rb_num2short()

short rb_num2short | ( | VALUE | num | ) |

Converts an instance of rb_cNumeric into C's `short`.

Parameters

  [in] | num | Something numeric.

Exceptions

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

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

Definition at line 3340 of file numeric.c.

Referenced by rb_num2short(), and rb_num2short_inline().

## ◆ rb_num2short_inline()

static short rb_num2short_inline | ( | VALUE | x | ) |
| inlinestatic

Identical to rb_num2short().

Parameters

  [in] | x | Something numeric.

Exceptions

  rb_eTypeError | `x` is not a numeric.
  rb_eRangeError | `x` is out of range of `short`.

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

Definition at line 105 of file short.h.

## ◆ rb_num2ushort()

unsigned short rb_num2ushort | ( | VALUE | num | ) |

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

Parameters

  [in] | num | Something numeric.

Exceptions

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

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

Definition at line 3358 of file numeric.c.

Referenced by rb_fix2ushort(), and rb_num2ushort().