Skip to content

Commit

Permalink
Add licensing info and package level docs
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed May 21, 2020
1 parent 17d8edb commit 00e29bc
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 6 deletions.
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2020 Denis Bernard <[email protected]>. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 changes: 27 additions & 0 deletions LICENSE-go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions dec.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
4 changes: 4 additions & 0 deletions dec_arith.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
2 changes: 1 addition & 1 deletion dec_arith_amd64.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
4 changes: 4 additions & 0 deletions dec_arith_decl.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !decimal_pure_go,amd64

package decimal
Expand Down
4 changes: 4 additions & 0 deletions dec_arith_decl_pure.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build decimal_pure_go !amd64

package decimal
Expand Down
4 changes: 4 additions & 0 deletions dec_arith_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
4 changes: 4 additions & 0 deletions dec_conv.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
2 changes: 1 addition & 1 deletion dec_conv_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
2 changes: 1 addition & 1 deletion dec_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
4 changes: 4 additions & 0 deletions decimal.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
4 changes: 4 additions & 0 deletions decimal_conv.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
2 changes: 1 addition & 1 deletion decimal_marsh.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
4 changes: 4 additions & 0 deletions decimal_sqrt.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
4 changes: 4 additions & 0 deletions decimal_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package decimal

import (
Expand Down
2 changes: 1 addition & 1 deletion decimal_toa.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

Expand Down
93 changes: 93 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
Package decimal implements arbitrary-precision decimal floating-point
arithmetic.
The implementation is heavily based on big.Float and besides a few additional
getters and setters for other math/big types, the API is identical to that of
*big.Float.
Howvever, and unlike big.Float, the mantissa of a decimal is stored in a
little-endian Word slice as "declets" of 9 or 19 decimal digits per 32 or 64
bits Word. All arithmetic operations are performed directly in base 10**9 or
10**19 without conversion to/from binary.
The zero value for a Decimal corresponds to 0. Thus, new values can be declared
in the usual ways and denote 0 without further initialization:
x := new(Decimal) // x is a *Decimal of value 0
Alternatively, new Decimal values can be allocated and initialized with the
function:
func NewDecimal(f float64) *Decimal
For instance, NewDecimal(x) returns a *Decimal set to the value of the float64
argument f. More flexibility is provided with explicit setters, for instance:
z := new(Float).SetUint64(123) // z3 := 123.0
Setters, numeric operations and predicates are represented as methods of the
form:
func (z *Decimal) SetV(v V) *Decimal // z = v
func (z *Decimal) Unary(x *Decimal) *Decimal // z = unary x
func (z *Decimal) Binary(x, y *Decimal) *Decimal // z = x binary y
func (x *Decimal) Pred() P // p = pred(x)
For unary and binary operations, the result is the receiver (usually named z in
that case; see below); if it is one of the operands x or y it may be safely
overwritten (and its memory reused).
Arithmetic expressions are typically written as a sequence of individual method
calls, with each call corresponding to an operation. The receiver denotes the
result and the method arguments are the operation's operands. For instance,
given three *Decimal values a, b and c, the invocation
c.Add(a, b)
computes the sum a + b and stores the result in c, overwriting whatever value
was held in c before. Unless specified otherwise, operations permit aliasing of
parameters, so it is perfectly ok to write
sum.Add(sum, x)
to accumulate values x in a sum.
(By always passing in a result value via the receiver, memory use can be much
better controlled. Instead of having to allocate new memory for each result, an
operation can reuse the space allocated for the result value, and overwrite that
value with the new result in the process.)
Notational convention: Incoming method parameters (including the receiver) are
named consistently in the API to clarify their use. Incoming operands are
usually named x, y, a, b, and so on, but never z. A parameter specifying the
result is named z (typically the receiver).
For instance, the arguments for (*Decimal).Add are named x and y, and because
the receiver specifies the result destination, it is called z:
func (z *Decimal) Add(x, y *Decimal) *Decimal
Methods of this form typically return the incoming receiver as well, to enable
simple call chaining.
Methods which don't require a result value to be passed in (for instance,
Decimal.Sign), simply return the result. In this case, the receiver is typically
the first operand, named x:
func (x *Decimal) Sign() int
Various methods support conversions between strings and corresponding numeric
values, and vice versa: Decimal implements the Stringer interface for a
(default) string representation of the value, but also provides SetString
methods to initialize a Decimal value from a string in a variety of supported
formats (see the SetString documentation).
Finally, *Decimal satisfies the fmt package's Scanner interface for scanning and
the Formatter interface for formatted printing.
*/
package decimal
6 changes: 5 additions & 1 deletion stdlib.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// This file mirrors types and constants from math/big.
// Copyright 2020 Denis Bernard <[email protected]>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This file mirrors constants, types and some internal functions from math/big.

package decimal

Expand Down

0 comments on commit 00e29bc

Please sign in to comment.