struct Float16

Overview

Float16 (also called half in other languages) is an implementation of the IEEE 754 half-precision binary floating-point format This implementation is ported from https://github.com/mm2/Little-CMS/blob/c6d1c9c07cfd03642d154973d036fccc59a2075c/src/cmshalf.c

Defined in:

float16cr.cr

Constant Summary

VERSION = "0.1.0"

Constructors

Instance Method Summary

Constructor Detail

def self.new(value : String, whitespace : Bool = true, strict : Bool = true) : self #

Returns a Float16 by invoking String#to_f32#to_f16 on value.

Float64.new "20"                        # => 20.0
Float64.new "  20  ", whitespace: false # => Unhandled exception: Invalid Float64:   20 (ArgumentError)

[View source]
def self.new(value : Float32) #

[View source]
def self.new(value) : self #

[View source]
def self.new!(value) : self #

Returns a Float16 by invoking to_f16! on value.


[View source]

Instance Method Detail

def !=(other : Int8) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Int16) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Int32) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Int64) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Int128) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : UInt8) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : UInt16) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : UInt32) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : UInt64) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : UInt128) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Float16) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Float32) : Bool #

Returns true if self is not equal to other.


[View source]
def !=(other : Float64) : Bool #

Returns true if self is not equal to other.


[View source]
def *(other : Int8) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Int16) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Int32) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Int64) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Int128) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : UInt8) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : UInt16) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : UInt32) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : UInt64) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : UInt128) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Float16) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Float32) : Float16 #

Returns the result of multiplying self and other.


[View source]
def *(other : Float64) : Float16 #

Returns the result of multiplying self and other.


[View source]
def **(other : Int32) : Float16 #

[View source]
def +(other : Int8) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Int16) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Int32) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Int64) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Int128) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : UInt8) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : UInt16) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : UInt32) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : UInt64) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : UInt128) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Float16) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Float32) : Float16 #

Returns the result of adding self and other.


[View source]
def +(other : Float64) : Float16 #

Returns the result of adding self and other.


[View source]
def -(other : Int8) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Int16) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Int32) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Int64) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Int128) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : UInt8) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : UInt16) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : UInt32) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : UInt64) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : UInt128) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Float16) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Float32) : Float16 #

Returns the result of subtracting self and other.


[View source]
def -(other : Float64) : Float16 #

Returns the result of subtracting self and other.


[View source]
def /(other : Int8) : Float16 #

[View source]
def /(other : UInt8) : Float16 #

[View source]
def /(other : Int16) : Float16 #

[View source]
def /(other : UInt16) : Float16 #

[View source]
def /(other : Int32) : Float16 #

[View source]
def /(other : UInt32) : Float16 #

[View source]
def /(other : Int64) : Float16 #

[View source]
def /(other : UInt64) : Float16 #

[View source]
def /(other : Int128) : Float16 #

[View source]
def /(other : UInt128) : Float16 #

[View source]
def /(other : Float64) : Float64 #

[View source]
def /(other : Float32) : Float32 #

[View source]
def /(other : Float16) : Float16 #

Returns the result of division self and other.


[View source]
def /(other : BigInt) : BigFloat #

[View source]
def /(other : BigFloat) : BigFloat #

[View source]
def /(other : BigDecimal) : BigDecimal #

[View source]
def /(other : BigRational) : BigRational #

[View source]
def <(other : Int8) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Int16) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Int32) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Int64) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Int128) : Bool #

Returns true if self is less than other.


[View source]
def <(other : UInt8) : Bool #

Returns true if self is less than other.


[View source]
def <(other : UInt16) : Bool #

Returns true if self is less than other.


[View source]
def <(other : UInt32) : Bool #

Returns true if self is less than other.


[View source]
def <(other : UInt64) : Bool #

Returns true if self is less than other.


[View source]
def <(other : UInt128) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Float16) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Float32) : Bool #

Returns true if self is less than other.


[View source]
def <(other : Float64) : Bool #

Returns true if self is less than other.


[View source]
def <=(other : Int8) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Int16) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Int32) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Int64) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Int128) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : UInt8) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : UInt16) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : UInt32) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : UInt64) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : UInt128) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Float16) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Float32) : Bool #

Returns true if self is less than or equal to other.


[View source]
def <=(other : Float64) : Bool #

Returns true if self is less than or equal to other.


[View source]
def ==(other : Int8) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Int16) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Int32) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Int64) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Int128) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : UInt8) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : UInt16) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : UInt32) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : UInt64) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : UInt128) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Float16) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Float32) : Bool #

Returns true if self is equal to other.


[View source]
def ==(other : Float64) : Bool #

Returns true if self is equal to other.


[View source]
def >(other : Int8) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Int16) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Int32) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Int64) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Int128) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : UInt8) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : UInt16) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : UInt32) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : UInt64) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : UInt128) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Float16) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Float32) : Bool #

Returns true if self is greater than other.


[View source]
def >(other : Float64) : Bool #

Returns true if self is greater than other.


[View source]
def >=(other : Int8) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Int16) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Int32) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Int64) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Int128) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : UInt8) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : UInt16) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : UInt32) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : UInt64) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : UInt128) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Float16) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Float32) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def >=(other : Float64) : Bool #

Returns true if self is greater than or equal to other.


[View source]
def ceil : Float16 #

[View source]
def clone #

[View source]
def fdiv(other : Int8) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Int16) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Int32) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Int64) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Int128) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : UInt8) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : UInt16) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : UInt32) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : UInt64) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : UInt128) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Float16) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Float32) : Float16 #

Returns the float division of self and other.


[View source]
def fdiv(other : Float64) : Float16 #

Returns the float division of self and other.


[View source]
def floor : Float16 #

[View source]
def round_away : Float16 #

Rounds towards the nearest integer. If both neighboring integers are equidistant, rounds away from zero.


[View source]
def round_even : Float16 #

Rounds towards the nearest integer. If both neighboring integers are equidistant, rounds towards the even neighbor (Banker's rounding).


[View source]
def to_f : Float64 #

Returns self converted to Float64. Raises OverflowError in case of overflow.


[View source]
def to_f! : Float64 #

Returns self converted to Float64. In case of overflow infinity is returned.


[View source]
def to_f32 : Float32 #

[View source]
def to_f64 : Float64 #

Returns self converted to Float64. Raises OverflowError in case of overflow.


[View source]
def to_f64! : Float64 #

Returns self converted to Float64. In case of overflow infinity is returned.


[View source]
def to_i : Int32 #

Returns self converted to Int32. Raises OverflowError in case of overflow.


[View source]
def to_i! : Int32 #

Returns self converted to Int32. In case of overflow infinity is returned.


[View source]
def to_i128 : Int128 #

Returns self converted to Int128. Raises OverflowError in case of overflow.


[View source]
def to_i128! : Int128 #

Returns self converted to Int128. In case of overflow infinity is returned.


[View source]
def to_i16 : Int16 #

Returns self converted to Int16. Raises OverflowError in case of overflow.


[View source]
def to_i16! : Int16 #

Returns self converted to Int16. In case of overflow infinity is returned.


[View source]
def to_i32 : Int32 #

Returns self converted to Int32. Raises OverflowError in case of overflow.


[View source]
def to_i32! : Int32 #

Returns self converted to Int32. In case of overflow infinity is returned.


[View source]
def to_i64 : Int64 #

Returns self converted to Int64. Raises OverflowError in case of overflow.


[View source]
def to_i64! : Int64 #

Returns self converted to Int64. In case of overflow infinity is returned.


[View source]
def to_i8 : Int8 #

Returns self converted to Int8. Raises OverflowError in case of overflow.


[View source]
def to_i8! : Int8 #

Returns self converted to Int8. In case of overflow infinity is returned.


[View source]
def to_s(io : IO) : Nil #
Description copied from class Object

Prints a nicely readable and concise string representation of this object, typically intended for users, to io.

This method is called when an object is interpolated in a string literal:

"foo #{bar} baz" # calls bar.to_io with the builder for this string

IO#<< calls this method to append an object to itself:

io << bar # calls bar.to_s(io)

Thus implementations must not interpolate self in a string literal or call io << self which both would lead to an endless loop.

Also see #inspect(IO).


[View source]
def to_s : String #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def to_u : UInt32 #

Returns self converted to UInt32. Raises OverflowError in case of overflow.


[View source]
def to_u! : UInt32 #

Returns self converted to UInt32. In case of overflow infinity is returned.


[View source]
def to_u128 : UInt128 #

Returns self converted to UInt128. Raises OverflowError in case of overflow.


[View source]
def to_u128! : UInt128 #

Returns self converted to UInt128. In case of overflow infinity is returned.


[View source]
def to_u16 : UInt16 #

Returns self converted to UInt16. Raises OverflowError in case of overflow.


[View source]
def to_u16! : UInt16 #

Returns self converted to UInt16. In case of overflow infinity is returned.


[View source]
def to_u32 : UInt32 #

Returns self converted to UInt32. Raises OverflowError in case of overflow.


[View source]
def to_u32! : UInt32 #

Returns self converted to UInt32. In case of overflow infinity is returned.


[View source]
def to_u64 : UInt64 #

Returns self converted to UInt64. Raises OverflowError in case of overflow.


[View source]
def to_u64! : UInt64 #

Returns self converted to UInt64. In case of overflow infinity is returned.


[View source]
def to_u8 : UInt8 #

Returns self converted to UInt8. Raises OverflowError in case of overflow.


[View source]
def to_u8! : UInt8 #

Returns self converted to UInt8. In case of overflow infinity is returned.


[View source]
def trunc : Float16 #

[View source]