Class: Flt::C51BCDFormat
- Inherits:
-
BCDFormat
- Object
- FormatBase
- DecimalFormatBase
- BCDFormat
- Flt::C51BCDFormat
- Defined in:
- lib/float-formats/formats.rb
Overview
C51 (C compiler for the Intel 8051) BCD Floating point formats
Constant Summary
Constants included from Flt
APPLE, IEEE_128, IEEE_128_BE, IEEE_DEC128, IEEE_DEC32, IEEE_DEC64, IEEE_DOUBLE, IEEE_D_BE, IEEE_EXTENDED, IEEE_HALF, IEEE_H_BE, IEEE_QUAD, IEEE_Q_BE, IEEE_SINGLE, IEEE_S_BE, IEEE_X_BE, IEEE_binaryx, RPL, RPL_X
Instance Attribute Summary
Attributes inherited from FormatBase
#exponent, #sign, #significand
Class Method Summary collapse
- .bcd_field?(i) ⇒ Boolean
- .exponent_digits ⇒ Object
-
.exponent_radix ⇒ Object
:nodoc:.
- .minus_sign_value ⇒ Object
- .pack(s, m, e) ⇒ Object
- .unpack(v) ⇒ Object
Methods inherited from BCDFormat
define, pack_fields, total_bits, total_bytes, total_nibbles, unpack_fields
Methods inherited from DecimalFormatBase
decimal_digits_necessary, decimal_digits_stored, decimal_max_exp, decimal_min_exp, define, radix, radix_log, radix_log10, radix_power
Methods inherited from FormatBase
#<=>, arithmetic, arithmetic_type, bias, canonicalized, context, #convert_to, decimal_digits_necessary, decimal_digits_stored, decimal_max_exp, decimal_min_exp, define, endianness, epsilon, #form_class, #fp_format, from, from_bits, from_bits_text, from_bytes, from_hex, from_number, from_text, gradual_underflow?, half_epsilon, #infinite?, infinity, #initialize, join, max_value, maximum_integral_significand, min_normalized_value, min_value, minimum_normalized_integral_significand, #minus, nan, #nan?, #next_minus, #next_plus, #normal?, num, num_class, numerals_conversion, pack_fields_hash, radix_log, radix_log10, radix_max_exp, radix_min_exp, radix_power, rounding_mode, sign_from_unit, sign_to_unit, #split, strict_epsilon, #subnormal?, switch_sign_value, #to, #to_a, #to_bits, #to_bits_text, #to_bytes, #to_hex, #to_num, #to_text, #ulp, unpack_fields_hash, zero, #zero?
Methods included from Flt
#*, #+, #-, #-@, #/, bcd2dpd, bitnot, convert_bytes, dbl_from_float, dbl_from_text, dbl_to_float, define, dpd2bcd, dpd_to_hexbcd, float_bin, float_dec, float_from_integral_sign_significand_exponent, float_from_integral_significand_exponent, float_shortest_dec, float_significant_dec, float_to_integral_sign_significand_exponent, float_to_integral_significand_exponent, hex_from_float, hex_to_float, hexbcd_to_dpd, sgl_from_float, sgl_from_text, sgl_to_float
Constructor Details
This class inherits a constructor from Flt::FormatBase
Class Method Details
.bcd_field?(i) ⇒ Boolean
565 566 567 |
# File 'lib/float-formats/formats.rb', line 565 def self.bcd_field?(i) @field_meaning[i]==:significand end |
.exponent_digits ⇒ Object
536 537 538 |
# File 'lib/float-formats/formats.rb', line 536 def self.exponent_digits @fields[:exponent_sign]*4-1 end |
.exponent_radix ⇒ Object
:nodoc:
533 534 535 |
# File 'lib/float-formats/formats.rb', line 533 def self.exponent_radix 2 end |
.minus_sign_value ⇒ Object
539 540 541 |
# File 'lib/float-formats/formats.rb', line 539 def self.minus_sign_value 1 end |
.pack(s, m, e) ⇒ Object
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/float-formats/formats.rb', line 569 def self.pack(s,m,e) s = sign_from_unit(s) msb = radix_power(@significand_digits-1) es = 0 if e==:zero e = @zero_encoded_exp m = 0 elsif e==:infinity e = @infinite_encoded_exp || radix_power(@fields[:exponent])-1 m = 0 elsif e==:nan e = @infinite_encoded_exp || radix_power(@fields[:exponent])-1 s = minus_sign_value # ? m = radix_power(@significand_digits-2) if m==0 elsif e==:denormal e = @denormal_encoded_exp else # to do: try to adjust m to keep e in range if out of valid range # to do: reduce m and adjust e if m too big min_exp = radix_min_exp(:integral_significand) if m>0 while m<msb && e>min_exp e -= 1 m *= radix end end if m<msb && @denormal_encoded_exp e = @denormal_encoded_exp elsif m==0 # => && @denormal_encoded_exp.nil? e = 0 else e = encode_exponent(e, :integral_significand) end end exp_bits = exponent_digits e_s = e + (s << exp_bits) pack_fields_hash significand: m, exponent_sign: e_s end |
.unpack(v) ⇒ Object
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/float-formats/formats.rb', line 542 def self.unpack(v) f = unpack_fields_hash(v) m = f[:significand] e_s = f[:exponent_sign] exp_bits = exponent_digits e = e_s & (2**exp_bits-1) s = e_s >> exp_bits if m==0 # +-zero e = :zero elsif @infinite_encoded_exp && e==@infinite_encoded_exp && m==0 # +-inifinity e = :infinity elsif @nan_encoded_exp && e==@nan_encoded_exp && m!=0 # NaN e = :nan else # normalized number e = decode_exponent(e, :integral_significand) end s = sign_to_unit(s) [s,m,e] end |