vpnumber

package
v0.0.0-...-bf055c7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2019 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package vpnumber handles fixed point numbers, on 32 or 64 bits. It comes with basic conversions and mathematical operations.

Index

Constants

View Source
const F32Const0 float32 = 0.0

F32Const0 contains 0 as a float32.

View Source
const F32Const1 float32 = 1.0

F32Const1 contains 1 as a float32.

View Source
const F64Const0 float64 = 0.0

F64Const0 contains 0 as a float64.

View Source
const F64Const1 float64 = 1.0

F64Const1 contains 1 as a float64.

View Source
const I32Const0 int32 = 0

I32Const0 contains 0 as an int32.

View Source
const I32Const1 int32 = 1

I32Const1 contains 1 as an int32.

View Source
const I64Const0 int64 = 0

I64Const0 contains 0 as an int64.

View Source
const I64Const1 int64 = 1

I64Const1 contains 1 as an int64.

View Source
const PackageCopyright = "Copyright (C)  2015, 2016  Christian Mauduit <ufoot@ufoot.org>" // PackageCopyright set by version.sh

PackageCopyright contains a short copyright notice.

View Source
const PackageEmail = "ufoot@ufoot.org" // PackageEmail set by version.sh

PackageEmail contains a contact email for the package.

View Source
const PackageLicense = "GNU GPL v3" // PackageLicense set by version.sh

PackageLicense contains a short license information.

View Source
const PackageName = "Vapor Toolkit" // PackageName set by version.sh

PackageName contains a readable name of the package, suitable for display.

View Source
const PackageTarname = "vapor" // PackageTarname set by version.sh

PackageTarname contains a short name of the package, suitable for a filename.

View Source
const PackageURL = "https://github.com/ufoot/vapor" // PackageURL set by version.sh

PackageURL contains the address of the project homepage.

View Source
const VersionMajor = 0 // VersionMajor set by version.sh

VersionMajor is the project major version.

View Source
const VersionMinor = 3 // VersionMinor set by version.sh

VersionMinor is the project minor version.

View Source
const VersionStamp = "c6a4298" // VersionStamp set by version.sh

VersionStamp is the project stamp, possibly changes for each build.

View Source
const X32Shift = 16

X32Shift tells how many bits must be shifted to convert a fixed point number on 32 bits to its int32 corresponding value.

View Source
const X64Shift = 32

X64Shift tells how many bits must be shifted to convert a fixed point number on 64 bits to its int64 corresponding value.

Variables

This section is empty.

Functions

func F32Div

func F32Div(f1 float32, f2 float32) float32

F32Div does a simple division, without raising any error on division by zero. Instead it will divide by the smallest value available, the results will probably be inconsistent but at least no panic around, program flow is not interrupted.

func F32IsSimilar

func F32IsSimilar(f1 float32, f2 float32) bool

F32IsSimilar returns true if args are approximatively the same. This is a workarround to ignore rounding errors.

func F32Round

func F32Round(f float32) float32

F32Round rounds to the nearest integer, while still returning a floating point value.

func F64Div

func F64Div(f1 float64, f2 float64) float64

F64Div does a simple division, without raising any error on division by zero. Instead it will divide by the smallest value available, the results will probably be inconsistent but at least no panic around, program flow is not interrupted.

func F64IsSimilar

func F64IsSimilar(f1 float64, f2 float64) bool

F64IsSimilar returns true if args are approximatively the same. This is a workarround to ignore rounding errors.

func F64Round

func F64Round(f float64) float64

F64Round rounds to the nearest integer, while still returning a floating point value.

func X32Exponent

func X32Exponent(x X32) int

X32Exponent returns the exponent of a fixed point number on 32 bits. This means a logical value of 1 has an exponent of 0, and the smallest strictly positive integer has an exponent of -16. 0 returns 0.

func X32IsSimilar

func X32IsSimilar(x1 X32, x2 X32) bool

X32IsSimilar returns true if args are approximatively the same. This is a workarround to ignore rounding errors.

func X32ToF32

func X32ToF32(x X32) float32

X32ToF32 converts a fixed point number on 32 bits to a float32.

func X32ToF64

func X32ToF64(x X32) float64

X32ToF64 converts a fixed point number on 32 bits to a float64.

func X32ToI32

func X32ToI32(x X32) int32

X32ToI32 converts a fixed point number on 32 bits to an int32.

func X32ToI64

func X32ToI64(x X32) int64

X32ToI64 converts a fixed point number on 32 bits to an int64.

func X64Exponent

func X64Exponent(x X64) int

X64Exponent returns the exponent of a fixed point number on 64 bits. This means a logical value of 1 has an exponent of 0, and the smallest strictly positive integer has an exponent of -32. 0 returns 0.

func X64IsSimilar

func X64IsSimilar(x1 X64, x2 X64) bool

X64IsSimilar returns true if args are approximatively the same. This is a workarround to ignore rounding errors.

func X64ToF32

func X64ToF32(x X64) float32

X64ToF32 converts a fixed point number on 64 bits to a float32.

func X64ToF64

func X64ToF64(x X64) float64

X64ToF64 converts a fixed point number on 64 bits to a float64.

func X64ToI32

func X64ToI32(x X64) int32

X64ToI32 converts a fixed point number on 64 bits to an int32.

func X64ToI64

func X64ToI64(x X64) int64

X64ToI64 converts a fixed point number on 64 bits to an int64.

Types

type X32

type X32 int32

X32 is a fixed point number on 32 bits. The idea is to arbitrary consider that 2^16 is 1, the 16 strongest bits being the integer part, and the 16 weakest bits being the fractionnal part. This might sound useless as all modern systems do have floats but in some cases it's convenient to have accurate integer calculations representing decimal numbers.

const X32Const0 X32 = 0

X32Const0 contains 0 as a fixed point number on 32 bits.

const X32Const1 X32 = 0x10000

X32Const1 contains 1 as a fixed point number on 32 bits.

func F32ToX32

func F32ToX32(f float32) X32

F32ToX32 converts a float32 to a fixed point number on 32 bits.

func F64ToX32

func F64ToX32(f float64) X32

F64ToX32 converts a float64 to a fixed point number on 32 bits.

func I32ToX32

func I32ToX32(i int32) X32

I32ToX32 converts an int32 to a fixed point number on 32 bits.

func I64ToX32

func I64ToX32(i int64) X32

I64ToX32 converts an int64 to a fixed point number on 32 bits.

func X32Abs

func X32Abs(x X32) X32

X32Abs returns the absolute value of a fixed point number on 32 bits.

func X32Ceil

func X32Ceil(x X32) X32

X32Ceil rounds a fixed point number on 32 bits to the nearest integer value just above. Casted as an integer the result has the 16 lowest bits set to 0.

func X32Div

func X32Div(x1 X32, x2 X32) X32

X32Div divides 2 fixed point numbers on 32 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Does not raise any error on division by zero. Instead it will divide by the smallest value available, the results will probably be inconsistent but at least no panic around, program flow is not interrupted. Beware of rounding errors, might be very approximative on limit cases.

func X32Divp

func X32Divp(x1 X32, x2 X32) X32

X32Divp divides 2 fixed point numbers on 32 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Does not raise any error on division by zero. Instead it will divide by the smallest value available, the results will probably be inconsistent but at least no panic around, program flow is not interrupted. Internally, this function uses 64 bits integers so that results have minimal rounding errors.

func X32Floor

func X32Floor(x X32) X32

X32Floor rounds a fixed point number on 32 bits to the integer value just below. Casted as an integer the result has the 16 lowest bits set to 0.

func X32Mantis

func X32Mantis(x X32) X32

X32Mantis returns the mantis of a fixed point number on 32 bits. Note that on numbers greater than 2 (exponent greater than 1) there is a loss of information as bits are shifted to the right.

func X32Max

func X32Max(x1 X32, x2 X32) X32

X32Max returns the maximum value bewteen 2 fixed point numbers on 32 bits.

func X32Min

func X32Min(x1 X32, x2 X32) X32

X32Min returns the minimum value bewteen 2 fixed point numbers on 32 bits.

func X32Mul

func X32Mul(x1 X32, x2 X32) X32

X32Mul multiplicates 2 fixed point numbers on 32 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Beware of rounding errors, might be very approximative on limit cases.

func X32Muln

func X32Muln(x X32, xn ...X32) X32

X32Muln multiplicates several fixed point numbers on 32 bits. Calls the 2 args mul function recursively. Beware of rounding errors, might be very approximative on limit cases.

func X32Mulp

func X32Mulp(x1 X32, x2 X32) X32

X32Mulp multiplicates 2 fixed point numbers on 32 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Internally, this function uses 64 bits integers so that results have minimal rounding errors.

func X32Round

func X32Round(x X32) X32

X32Round rounds a fixed point number on 32 bits to the nearest integer value. Casted as an integer the result has the 16 lowest bits set to 0.

func X64ToX32

func X64ToX32(x X64) X32

X64ToX32 converts a fixed point number on 64 bits to a fixed point number on 32 bits.

func (*X32) MarshalJSON

func (x *X32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*X32) String

func (x *X32) String() string

String returns a readable form of the matrix.

func (*X32) UnmarshalJSON

func (x *X32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type X64

type X64 int64

X64 is as fixed point number on 64 bits, the idea is to arbitrary consider that 2^32 is 1, the 32 strongest bits being the integer part, and the 32 weakest bits being the fractionnal part. This might sound useless as all modern systems do have floats but in some cases it's convenient to have accurate integer calculations representing decimal numbers.

const X64Const0 X64 = 0

X64Const0 contains 0 as a fixed point number on 64 bits.

const X64Const1 X64 = 0x100000000

X64Const1 contains 1 as a fixed point number on 64 bits.

func F32ToX64

func F32ToX64(f float32) X64

F32ToX64 cnverts a float32 to a fixed point number on 64 bits.

func F64ToX64

func F64ToX64(f float64) X64

F64ToX64 converts a float64 to a fixed point number on 64 bits.

func I32ToX64

func I32ToX64(i int32) X64

I32ToX64 converts an int32 to a fixed point number on 64 bits.

func I64ToX64

func I64ToX64(i int64) X64

I64ToX64 converts an int64 to a fixed point number on 64 bits.

func X32ToX64

func X32ToX64(x X32) X64

X32ToX64 converts a fixed point number on 32 bits to a fixed point number on 64 bits.

func X64Abs

func X64Abs(x X64) X64

X64Abs returns the absolute value of a fixed point number on 64 bits.

func X64Ceil

func X64Ceil(x X64) X64

X64Ceil rounds a fixed point number on 64 bits to the nearest integer value just above. Casted as an integer the result has the 32 lowest bits set to 0.

func X64Div

func X64Div(x1 X64, x2 X64) X64

X64Div divides 2 fixed point numbers on 64 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Does not raise any error on division by zero. Instead it will divide by the smallest value available, the results will probably be inconsistent but at least no panic around, program flow is not interrupted. Beware of rounding errors, might be very approximative on limit cases.

func X64Divp

func X64Divp(x1 X64, x2 X64) X64

X64Divp divides 2 fixed point numbers on 64 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Does not raise any error on division by zero. Instead it will divide by the smallest value available, the results will probably be inconsistent but at least no panic around, program flow is not interrupted. Internally, this function uses 128 bits integers so that results have minimal rounding errors. As a consequence, it is quite slow.

func X64Floor

func X64Floor(x X64) X64

X64Floor rounds a fixed point number on 64 bits to the integer value just below. Casted as an integer the result has the 32 lowest bits set to 0.

func X64Mantis

func X64Mantis(x X64) X64

X64Mantis returns the mantis of a fixed point number on 64 bits. Note that on numbers greater than 2 (exponent greater than 1) there is a loss of information as bits are shifted to the right.

func X64Max

func X64Max(x1 X64, x2 X64) X64

X64Max returns the maximum value bewteen 2 fixed point numbers on 64 bits.

func X64Min

func X64Min(x1 X64, x2 X64) X64

X64Min returns the minimum value bewteen 2 fixed point numbers on 64 bits.

func X64Mul

func X64Mul(x1 X64, x2 X64) X64

X64Mul multiplicates 2 fixed point numbers on 64 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Beware of rounding errors, might be very approximative on limit cases.

func X64Muln

func X64Muln(x X64, xn ...X64) X64

X64Muln multiplicates several fixed point numbers on 64 bits. Calls the 2 args mul function recursively. Beware of rounding errors, might be very approximative on limit cases.

func X64Mulp

func X64Mulp(x1 X64, x2 X64) X64

X64Mulp multiplicates 2 fixed point numbers on 64 bits. This is not equivalent to the standard * operator as values need be shifted so that they do not get artificially big. Internally, this function uses 128 bits integers so that results have minimal rounding errors. As a consequence, it is quite slow.

func X64Round

func X64Round(x X64) X64

X64Round rounds a fixed point number on 64 bits to the nearest integer value. Casted as an integer the result has the 32 lowest bits set to 0.

func (*X64) MarshalJSON

func (x *X64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*X64) String

func (x *X64) String() string

String returns a readable form of the matrix.

func (*X64) UnmarshalJSON

func (x *X64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL