Module: LibBin
- Defined in:
- lib/libbin.rb,
lib/libbin/data_types.rb,
ext/libbin/libbin_c.c
Overview
Container module, handles the global state default endianness and error output.
Defined Under Namespace
Modules: RangeRefinement Classes: DataRange, DataShape, Structure
Class Attribute Summary collapse
-
.big ⇒ Object
Returns the value of attribute big.
-
.output ⇒ Object
Returns the value of attribute output.
Class Method Summary collapse
-
.default_big? ⇒ Boolean
Returns true the default endianness is big.
-
.half_from_string(str, unpack_str) ⇒ Float
Load (unpacks) a half precision floating point.
-
.half_to_string(value, pack_str) ⇒ String
Convert a Numeric value to a half precision floating point and pack it into a string.
-
.pghalf_from_string(str, unpack_str) ⇒ Float
Load (unpacks) a half precision floating point as used by PlatinumGames in some formats.
-
.pghalf_to_string(value, pack_str) ⇒ String
Convert a Numeric value to a half precision floating point as used by PlatinumGames in some formats, and pack it into a string.
Class Attribute Details
.big ⇒ Object
Returns the value of attribute big.
12 13 14 |
# File 'lib/libbin.rb', line 12 def big @big end |
.output ⇒ Object
Returns the value of attribute output.
13 14 15 |
# File 'lib/libbin.rb', line 13 def output @output end |
Class Method Details
.default_big? ⇒ Boolean
Returns true the default endianness is big
17 18 19 |
# File 'lib/libbin.rb', line 17 def self.default_big? @big end |
.half_from_string(str, unpack_str) ⇒ Float
1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 |
# File 'ext/libbin/libbin_c.c', line 1788
static VALUE half_from_string_p(VALUE self, VALUE str, VALUE pack_str) {
(void)self;
Check_Type(str, T_STRING);
Check_Type(pack_str, T_STRING);
VALUE arr = rb_funcall(str, rb_intern("unpack"), 1, pack_str);
uint16_t val = NUM2USHORT(rb_funcall(arr, rb_intern("first"), 0));
union float_u res;
res.i = half_to_float(val);
return DBL2NUM(res.f);
}
|
.half_to_string(value, pack_str) ⇒ String
1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 |
# File 'ext/libbin/libbin_c.c', line 1813
static VALUE half_to_string_p(VALUE self, VALUE number, VALUE pack_str) {
(void)self;
Check_Type(number, T_FLOAT);
union float_u val;
uint16_t res;
val.f = NUM2DBL(number);
res = half_from_float(val.i);
VALUE arr = rb_ary_new3(1, UINT2NUM(res) );
return rb_funcall(arr, rb_intern("pack"), 1, pack_str);
}
|
.pghalf_from_string(str, unpack_str) ⇒ Float
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 |
# File 'ext/libbin/libbin_c.c', line 1776
static VALUE pghalf_from_string_p(VALUE self, VALUE str, VALUE pack_str) {
(void)self;
Check_Type(str, T_STRING);
Check_Type(pack_str, T_STRING);
VALUE arr = rb_funcall(str, rb_intern("unpack"), 1, pack_str);
uint16_t val = NUM2USHORT(rb_funcall(arr, rb_intern("first"), 0));
union float_u res;
res.i = pghalf_to_float(val);
return DBL2NUM(res.f);
}
|
.pghalf_to_string(value, pack_str) ⇒ String
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 |
# File 'ext/libbin/libbin_c.c', line 1800
static VALUE pghalf_to_string_p(VALUE self, VALUE number, VALUE pack_str) {
(void)self;
Check_Type(number, T_FLOAT);
union float_u val;
uint16_t res;
val.f = NUM2DBL(number);
res = pghalf_from_float(val.i);
VALUE arr = rb_ary_new3(1, UINT2NUM(res) );
return rb_funcall(arr, rb_intern("pack"), 1, pack_str);
}
|