Пример #1
0
// GreaterEqual is true if a >= b.
//
// The status fields of a and b are not checked.
// If you need to check them, you can call a.Error() and b.Error().
//
func (a Quad) GreaterEqual(b Quad) bool {
	var result C.uint32_t

	result = C.mdq_compare(C.struct_Quad(a), C.struct_Quad(b))

	if CmpFlag(result)&(CmpGreater|CmpEqual) != 0 {
		return true
	}

	return false
}
Пример #2
0
// Less is true if a < b.
//
// The status fields of a and b are not checked.
// If you need to check them, you can call a.Error() and b.Error().
//
func (a Quad) Less(b Quad) bool {
	var result C.uint32_t

	result = C.mdq_compare(C.struct_Quad(a), C.struct_Quad(b))

	if CmpFlag(result)&CmpLess != 0 {
		return true
	}

	return false
}
Пример #3
0
// ToInt64 returns the int64 value from a.
// The rounding passed as argument is used, instead of the rounding mode of context which is ignored.
//
// The status field of a is not checked.
// If you need to check the status of a, you can call a.Error().
//
// Note that ToInt64 is slower than ToInt32, because the underlying C decNumber package has no function that converts directly to int64.
// So, the number is first converted to string, and then to int64.
//
func (a Quad) ToInt64(rounding RoundingMode) (int64, error) {
	var result C.Ret_int64_t

	result = C.mdq_to_int64(C.struct_Quad(a), C.int(rounding))

	if Status(result.status)&ErrorMask != 0 {
		return 0, newError(Status(result.status))
	}

	return int64(result.val), nil
}
Пример #4
0
// Round rounds (or truncate) 'a', with RoundHalfEven mode.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
func (a Quad) Round(n int32) Quad {

	return Quad(C.mdq_roundM(C.struct_Quad(a), C.int32_t(n), C.int(RoundHalfEven)))
}
Пример #5
0
// DivInt returns the integral part of a/b.
//
func (a Quad) DivInt(b Quad) Quad {

	return Quad(C.mdq_divide_integer(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #6
0
// Quantize rounds a to the same pattern as b.
// b is just a model, its sign and coefficient value are ignored. Only its exponent is used.
// The result is the value of a, but with the same exponent as the pattern b.
//
//      The representation of a number is:
//
//           (-1)^sign  coefficient * 10^exponent
//           where coefficient is an integer storing 34 digits.
//
// Examples (with RoundHalfEven rounding mode):
//    quantization of 134.6454 with    0.00001    is   134.64540
//                    134.6454 with    0.00000    is   134.64540     the value of b has no importance
//                    134.6454 with 1234.56789    is   134.64540     the value of b has no importance
//                    134.6454 with 0.0001        is   134.6454
//                    134.6454 with 0.01          is   134.65
//                    134.6454 with 1             is   135
//                    134.6454 with 1000000000    is   135           the value of b has no importance
//                    134.6454 with 1E+2          is   1E+2
//
//		        123e32 with 1             sets Invalid_operation error flag in status
//		        123e32 with 1E1           is   1230000000000000000000000000000000E1
//		        123e32 with 10            sets Invalid_operation error flag in status
//
// See also Round, RoundMode and Truncate methods, which are more useful methods.
//
func (a Quad) Quantize(b Quad, rounding RoundingMode) Quad {

	return Quad(C.mdq_quantize(C.struct_Quad(a), C.struct_Quad(b), C.int(rounding)))
}
Пример #7
0
// Abs returns the absolute value of a.
//
func (a Quad) Abs() Quad {

	return Quad(C.mdq_abs(C.struct_Quad(a)))
}
Пример #8
0
// Min returns the smaller of a and b.
// If either a or b is NaN then the other argument is the result.
//
func Min(a Quad, b Quad) Quad {

	return Quad(C.mdq_min(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #9
0
// ToIntegral returns the value of a rounded to an integral value.
//
//      The representation of a number is:
//
//           (-1)^sign  coefficient * 10^exponent
//           where coefficient is an integer storing 34 digits.
//
//       - If exponent < 0, the least significant digits are discarded, so that new exponent becomes 0.
//             Internally, it calls Quantize(a, 1E0) with specified rounding.
//       - If exponent >= 0, the number remains unchanged.
//
//         E.g.     12.345678e2    is     12345678E-4     -->   1235E0
//                  123e5          is     123E5        remains   123E5
//
// See also Round, RoundMode and Truncate methods, which are more convenient to use.
//
func (a Quad) ToIntegral(rounding RoundingMode) Quad {

	return Quad(C.mdq_to_integral(C.struct_Quad(a), C.int(rounding)))
}
Пример #10
0
// Mod returns the modulo of a and b.
//
func (a Quad) Mod(b Quad) Quad {

	return Quad(C.mdq_remainder(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #11
0
// Max returns the larger of a and b.
// If either a or b is NaN then the other argument is the result.
//
func Max(a Quad, b Quad) Quad {

	return Quad(C.mdq_max(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #12
0
// Div returns a/b.
//
func (a Quad) Div(b Quad) Quad {

	return Quad(C.mdq_divide(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #13
0
// RoundWithMode rounds (or truncate) 'a', with the mode passed as argument.
// You must pass a constant RoundCeiling, RoundHalfEven, etc as argument.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
func (a Quad) RoundWithMode(n int32, rounding RoundingMode) Quad {

	return Quad(C.mdq_roundM(C.struct_Quad(a), C.int32_t(n), C.int(rounding)))
}
Пример #14
0
// Mul returns a * b.
//
func (a Quad) Mul(b Quad) Quad {

	return Quad(C.mdq_multiply(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #15
0
// Sub returns a - b.
//
func (a Quad) Sub(b Quad) Quad {

	return Quad(C.mdq_subtract(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #16
0
// Add returns a + b.
//
func (a Quad) Add(b Quad) Quad {

	return Quad(C.mdq_add(C.struct_Quad(a), C.struct_Quad(b)))
}
Пример #17
0
// Neg returns -a.
//
func (a Quad) Neg() Quad {

	return Quad(C.mdq_minus(C.struct_Quad(a)))
}
Пример #18
0
// Truncate truncates 'a'.
// It is like rounding with RoundDown.
//
//  n must be in the range [-35...34]. Else, Invalid Operation flag is set, and NaN is returned.
//
func (a Quad) Truncate(n int32) Quad {

	return Quad(C.mdq_roundM(C.struct_Quad(a), C.int32_t(n), C.int(RoundDown)))
}