struct Float::Printer::DiyFP

Overview

This "Do It Yourself Floating Point" struct implements a floating-point number with a `UIht64` significand and an `Int32` exponent. Normalized DiyFP numbers will have the most significant bit of the significand set. Multiplication and Subtraction do not normalize their results. DiyFP is not designed to contain special Floats (NaN and Infinity).

Defined in:

float/printer/diy_fp.cr

Constant Summary

MASK32 = `4294967295_u32`
SIGNIFICAND_SIZE = `64`

Instance Method Summary

, , , ,

,

Instance methods inherited from class `Object`

, , , , , , , , , , , , , , , , , , ,

,

Constructor Detail

def self.new(frac, exp : Int16) #

def self.new(frac, exp) #

Class Method Detail

def self.from_f(d : Float64 | Float32) #

def self.from_f_normalized(v : Float64 | Float32) #

Normalize such that the most signficiant bit of frac is set

Instance Method Detail

def *(other : DiyFP) #

Returns a new `DiyFP` caculated as self * other.

Simply "emulates" a 128 bit multiplication. However: the resulting number only contains 64 bits. The least significant 64 bits are only used for rounding the most significant 64 bits.

This result is not normalized.

def -(other : DiyFP) #

Returns a new `DiyFP` caculated as self - other.

The exponents of both numbers must be the same and the frac of self must be greater than the other.

This result is not normalized.

def exp : Int32 #

exponent

def exp=(exp : Int32) #

exponent

def frac : UInt64 #

Also known as the significand

def frac=(frac : UInt64) #

Also known as the significand

def new(frac : Int32, exp) #

def normalize #