Commit bba8b89a authored by Robert Griesemer's avatar Robert Griesemer

math/big: improve some doc strings

Change-Id: Ie37673d4af2fa7476d67ffb686641611ab6a8e6b
Reviewed-on: https://go-review.googlesource.com/5930Reviewed-by: 's avatarAlan Donovan <adonovan@google.com>
parent 7e93610b
...@@ -34,21 +34,23 @@ const debugFloat = true // enable for debugging ...@@ -34,21 +34,23 @@ const debugFloat = true // enable for debugging
// be rounded to fit into the mantissa bits, and accuracy describes the // be rounded to fit into the mantissa bits, and accuracy describes the
// rounding error with respect to the exact result. // rounding error with respect to the exact result.
// //
// All operations, including setters, that specify a *Float for the result, // All operations, including setters, that specify a *Float variable for
// usually via the receiver, round their result to the result's precision // the result (usually via the receiver with the exception of MantExp),
// and according to its rounding mode, unless specified otherwise. If the // round the numeric result according to the precision and rounding mode
// result precision is 0 (see below), it is set to the precision of the // of the result variable, unless specified otherwise.
// argument with the largest precision value before any rounding takes //
// If the result precision is 0 (see below), it is set to the precision of
// the argument with the largest precision value before any rounding takes
// place, and the rounding mode remains unchanged. Thus, uninitialized Floats // place, and the rounding mode remains unchanged. Thus, uninitialized Floats
// provided as result arguments will have their precision set to a reasonable // provided as result arguments will have their precision set to a reasonable
// value determined by the operands and their mode is the zero value for // value determined by the operands and their mode is the zero value for
// RoundingMode (ToNearestEven). // RoundingMode (ToNearestEven).
// //
// By setting the desired precision to 24 or 53 and using ToNearestEven // By setting the desired precision to 24 or 53 and using matching rounding
// rounding, Float operations produce the same results as the corresponding // mode (typically ToNearestEven), Float operations produce the same results
// float32 or float64 IEEE-754 arithmetic for normalized operands (no NaNs // as the corresponding float32 or float64 IEEE-754 arithmetic for normalized
// or denormalized numbers). Additionally, positive and negative zeros and // operands (no NaNs or denormalized numbers). Additionally, positive and
// infinities are fully supported. // negative zeros and infinities are fully supported.
// //
// The zero (uninitialized) value for a Float is ready to use and represents // The zero (uninitialized) value for a Float is ready to use and represents
// the number +0.0 exactly, with precision 0 and rounding mode ToNearestEven. // the number +0.0 exactly, with precision 0 and rounding mode ToNearestEven.
...@@ -203,8 +205,8 @@ func (x *Float) Sign() int { ...@@ -203,8 +205,8 @@ func (x *Float) Sign() int {
// It returns mant and exp satisfying x == mant × 2**exp, with // It returns mant and exp satisfying x == mant × 2**exp, with
// the absolute value of mant satisfying 0.5 <= |mant| < 1.0. // the absolute value of mant satisfying 0.5 <= |mant| < 1.0.
// mant has the same precision and rounding mode as x. // mant has the same precision and rounding mode as x.
// If a non-nil *Float argument z is provided it is used to // If a non-nil *Float argument z is provided, MantExp stores
// store the result mant; otherwise a new Float is allocated. // the result mant in z instead of allocating a new Float.
// //
// Special cases are: // Special cases are:
// //
...@@ -785,11 +787,12 @@ func (x *Float) Float64() (float64, Accuracy) { ...@@ -785,11 +787,12 @@ func (x *Float) Float64() (float64, Accuracy) {
return math.Float64frombits(s | e<<52 | m), r.acc return math.Float64frombits(s | e<<52 | m), r.acc
} }
// Int returns the result of truncating x towards zero; or nil // Int returns the result of truncating x towards zero;
// if x is an infinity. The result is Exact if x.IsInt(); // or nil if x is an infinity.
// otherwise it is Below for x > 0, and Above for x < 0. // The result is Exact if x.IsInt(); otherwise it is Below
// If a non-nil *Int argument z is provided, it is used to store // for x > 0, and Above for x < 0.
// the result; otherwise a new Int is allocated. // If a non-nil *Int argument z is provided, Int stores
// the result in z instead of allocating a new Int.
func (x *Float) Int(z *Int) (*Int, Accuracy) { func (x *Float) Int(z *Int) (*Int, Accuracy) {
if debugFloat { if debugFloat {
validate(x) validate(x)
...@@ -839,9 +842,10 @@ func (x *Float) Int(z *Int) (*Int, Accuracy) { ...@@ -839,9 +842,10 @@ func (x *Float) Int(z *Int) (*Int, Accuracy) {
return z, acc return z, acc
} }
// Rat returns x converted into an exact fraction; or nil if x is an infinity. // Rat returns the result of converting x into a quotient;
// If a non-nil *Rat argument z is provided, it is used to store the result; // or nil if x is an infinity.
// otherwise a new Rat is allocated. // If a non-nil *Rat argument z is provided, Rat stores
// the result in z instead of allocating a new Rat.
func (x *Float) Rat(z *Rat) *Rat { func (x *Float) Rat(z *Rat) *Rat {
if debugFloat { if debugFloat {
validate(x) validate(x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment