Skip to content

Commit

Permalink
float80x86: add scaffolding for x86 extended precision package
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Jul 6, 2018
1 parent 71fd1a7 commit 6b722e0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
[![Coverage Status](https://coveralls.io/repos/github/mewmew/floats/badge.svg?branch=master)](https://coveralls.io/github/mewmew/floats?branch=master)
[![GoDoc](https://godoc.org/github.com/mewmew/floats?status.svg)](https://godoc.org/github.com/mewmew/floats)

Binary floating-point formats.
Floating-point formats.

* [binary16](https://godoc.org/github.com/mewmew/floats/binary16) (IEEE 754 [half precision floating-point format](https://en.wikipedia.org/wiki/Half-precision_floating-point_format))
* [binary128](https://godoc.org/github.com/mewmew/floats/binary128) (IEEE 754 [quadruple precision floating-point format](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format))
* [binary16](https://godoc.org/github.com/mewmew/floats/binary16) (IEEE 754 [half precision](https://en.wikipedia.org/wiki/Half-precision_floating-point_format) floating-point format)
* [binary128](https://godoc.org/github.com/mewmew/floats/binary128) (IEEE 754 [quadruple precision](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format) floating-point format)
* [float80x86](https://godoc.org/github.com/mewmew/floats/float80x86) ([x86 extended precision](https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format) floating-point format)
* [float128ppc](https://godoc.org/github.com/mewmew/floats/float128ppc) ([IBM extended double](https://en.wikipedia.org/wiki/IBM_Floating_Point_Architecture#Extended-precision_128-bit) hexadecimal floating-point format)
14 changes: 7 additions & 7 deletions binary16/binary16.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ type Float struct {
// 1 bit: sign
// 5 bits: exponent
// 10 bits: fraction
a uint16
bits uint16
}

// NewFromBits returns the floating-point number corresponding to the IEEE 754
// half precision binary representation.
func NewFromBits(a uint16) Float {
return Float{a: a}
func NewFromBits(bits uint16) Float {
return Float{bits: bits}
}

// NewFromFloat32 returns the nearest half precision floating-point number for x
Expand All @@ -42,7 +42,7 @@ func NewFromFloat64(x float64) (f Float, exact bool) {

// Bits returns the IEEE 754 half precision binary representation of f.
func (f Float) Bits() uint16 {
return f.a
return f.bits
}

// Float32 returns the float32 representation of f.
Expand Down Expand Up @@ -123,17 +123,17 @@ func (f Float) big() *floats.Float {
// signbit reports whether f is negative or negative 0.
func (f Float) signbit() bool {
// 0b1000000000000000
return f.a&0x8000 != 0
return f.bits&0x8000 != 0
}

// exp returns the exponent of f.
func (f Float) exp() uint16 {
// 0b0111110000000000
return f.a & 0x7C00 >> 10
return f.bits & 0x7C00 >> 10
}

// mant returns the mantissa of f.
func (f Float) mant() uint16 {
// 0b0000001111111111
return f.a & 0x03FF
return f.bits & 0x03FF
}
52 changes: 52 additions & 0 deletions float80x86/float80x86.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Package float80x86 implements encoding and decoding of x86 extended precision
// floating-point numbers.
//
// https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format
package float80x86

// Float is a floating-point number in x86 extended precision format.
type Float struct {
// Sign and exponent.
//
// 1 bit: sign
// 15 bits: exponent
se uint16
// Integer part and fraction.
//
// 1 bit: integer part
// 63 bits: fraction
m uint64
}

// NewFromBits returns the floating-point number corresponding to the x86
// extended precision representation.
func NewFromBits(se uint16, m uint64) Float {
return Float{se: se, m: m}
}

// NewFromFloat32 returns the nearest x86 extended precision floating-point
// number for x and a bool indicating whether f represents x exactly.
func NewFromFloat32(x float32) (f Float, exact bool) {
panic("not yet implemented")
}

// NewFromFloat64 returns the nearest x86 extended precision floating-point
// number for x and a bool indicating whether f represents x exactly.
func NewFromFloat64(x float64) (f Float, exact bool) {
panic("not yet implemented")
}

// Bits returns the x86 extended precision binary representation of f.
func (f Float) Bits() (se uint16, m uint64) {
return f.se, f.m
}

// Float32 returns the float32 representation of f.
func (f Float) Float32() float32 {
panic("not yet implemented")
}

// Float64 returns the float64 representation of f.
func (f Float) Float64() float64 {
panic("not yet implemented")
}

0 comments on commit 6b722e0

Please sign in to comment.