Returns a value equal to 'a' (rounded), having the exponent of 'b'. The coefficient of the result is derived from that of the left-hand operand. It may be rounded using the current rounding setting (if the exponent is being increased), multiplied by a positive power of
(self, a, b)
| 5233 | return r |
| 5234 | |
| 5235 | def quantize(self, a, b): |
| 5236 | """Returns a value equal to 'a' (rounded), having the exponent of 'b'. |
| 5237 | |
| 5238 | The coefficient of the result is derived from that of the left-hand |
| 5239 | operand. It may be rounded using the current rounding setting (if the |
| 5240 | exponent is being increased), multiplied by a positive power of ten (if |
| 5241 | the exponent is being decreased), or is unchanged (if the exponent is |
| 5242 | already equal to that of the right-hand operand). |
| 5243 | |
| 5244 | Unlike other operations, if the length of the coefficient after the |
| 5245 | quantize operation would be greater than precision then an Invalid |
| 5246 | operation condition is raised. This guarantees that, unless there is |
| 5247 | an error condition, the exponent of the result of a quantize is always |
| 5248 | equal to that of the right-hand operand. |
| 5249 | |
| 5250 | Also unlike other operations, quantize will never raise Underflow, even |
| 5251 | if the result is subnormal and inexact. |
| 5252 | |
| 5253 | >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.001')) |
| 5254 | Decimal('2.170') |
| 5255 | >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.01')) |
| 5256 | Decimal('2.17') |
| 5257 | >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.1')) |
| 5258 | Decimal('2.2') |
| 5259 | >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+0')) |
| 5260 | Decimal('2') |
| 5261 | >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+1')) |
| 5262 | Decimal('0E+1') |
| 5263 | >>> ExtendedContext.quantize(Decimal('-Inf'), Decimal('Infinity')) |
| 5264 | Decimal('-Infinity') |
| 5265 | >>> ExtendedContext.quantize(Decimal('2'), Decimal('Infinity')) |
| 5266 | Decimal('NaN') |
| 5267 | >>> ExtendedContext.quantize(Decimal('-0.1'), Decimal('1')) |
| 5268 | Decimal('-0') |
| 5269 | >>> ExtendedContext.quantize(Decimal('-0'), Decimal('1e+5')) |
| 5270 | Decimal('-0E+5') |
| 5271 | >>> ExtendedContext.quantize(Decimal('+35236450.6'), Decimal('1e-2')) |
| 5272 | Decimal('NaN') |
| 5273 | >>> ExtendedContext.quantize(Decimal('-35236450.6'), Decimal('1e-2')) |
| 5274 | Decimal('NaN') |
| 5275 | >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-1')) |
| 5276 | Decimal('217.0') |
| 5277 | >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-0')) |
| 5278 | Decimal('217') |
| 5279 | >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+1')) |
| 5280 | Decimal('2.2E+2') |
| 5281 | >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+2')) |
| 5282 | Decimal('2E+2') |
| 5283 | >>> ExtendedContext.quantize(1, 2) |
| 5284 | Decimal('1') |
| 5285 | >>> ExtendedContext.quantize(Decimal(1), 2) |
| 5286 | Decimal('1') |
| 5287 | >>> ExtendedContext.quantize(1, Decimal(2)) |
| 5288 | Decimal('1') |
| 5289 | """ |
| 5290 | a = _convert_other(a, raiseit=True) |
| 5291 | return a.quantize(b, context=self) |
| 5292 |
nothing calls this directly
no test coverage detected