// 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 rounding of the context is used. // // You can use this function with the proper rounding to round (e.g. set context rounding mode to ROUND_HALF_EVEN) or truncate (ROUND_DOWN) 'a'. // // The representation of a number is: // // (-1)^sign coefficient * 10^exponent // where coefficient is an integer storing 34 digits. // // Examples: // 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 easier to use. // func (context *Context) Quantize(a Quad, b Quad) (r Quad) { var result C.Ret_decQuad_t assert_sane(context) result = C.mdq_quantize(a.val, b.val, context.set) context.set = result.set return Quad{val: result.val} }
// 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))) }