Issue8786
Created on 2010-05-22 10:28 by mark.dickinson, last changed 2010-05-22 22:21 by mark.dickinson.
| Messages (5) | |||
|---|---|---|---|
| msg106294 - (view) | Author: Mark Dickinson (mark.dickinson) * ![]() |
Date: 2010-05-22 10:28 | |
Discussion migrated from issue 8540 into its own issue. For ease of communication with other libraries, it would be good to be able to easily create contexts corresponding to the IEEE 754 (2008) decimal interchange formats. |
|||
| msg106296 - (view) | Author: Stefan Krah (skrah) * ![]() |
Date: 2010-05-22 11:24 | |
Some context from issue 8540: [Stefan Krah] > I'm busy implementing the IEEE754 contexts for cdecimal. To keep things > in sync, it would be nice to agree how they should be created. > > > Suggestions: > > 1) c = Decimal64Context > > 2) c = Context(Decimal64) [Mark Dickinson] > Rather that complicating the Context constructor, I'd prefer a separate factory > function. I was thinking of something like: > > def IEEEContext(n): > """Return the decimal<n> IEEE 754 context. n should be a multiple > of 32.""" > ... > > Again, it's clear with this that you get a new context object (I agree that > there are problems with (1) and the mutability of Contexts). I like that, too. Where do you find the "multiple of 32" in the standard? In a draft of IEEE 754, I only see: Table 2—Interchange format parameters defining floating-point numbers: storage format: decimal32 basic format: decimal64 and decimal128 This is what Java and decNumber offer. |
|||
| msg106297 - (view) | Author: Mark Dickinson (mark.dickinson) * ![]() |
Date: 2010-05-22 11:29 | |
It's Table 3.6 ("Decimal interchange format parameters") in the final version of IEEE 754; I'm not sure what that corresponds to in the various drafts. It has column headings: "decimal32", "decimal64", "decimal128" and "decimal{k} (k >= 32)".
Parameters for decimal{k}: k must be a multiple of 32. precision is 9*k/32-2. emax is 3*2**(k/16+3). I think these formulas all work for the specific cases k in {32, 64, 128} too, so it should be easy to check that they make sense.
They give an example below the table, too:
"For example, decimal256 would have p = 70 and emax = 1572864."
|
|||
| msg106303 - (view) | Author: Stefan Krah (skrah) * ![]() |
Date: 2010-05-22 12:07 | |
Mark Dickinson <report@bugs.python.org> wrote: > It's Table 3.6 ("Decimal interchange format parameters") in the final version of IEEE 754; Thanks! I think this is not in the draft I have. +1 for IEEEContext(n). Could we have module constants Decimal32, Decimal64 and Decimal128 so that people coming from Java or DecNumber can write: c = IEEEContext(Decimal64) It is somewhat redundant, but 99% of people will use only those. |
|||
| msg106325 - (view) | Author: Mark Dickinson (mark.dickinson) * ![]() |
Date: 2010-05-22 22:21 | |
Thinking ahead a bit: at some point we might well also want functions to pack and unpack these IEEE formats into byte sequences, using the bit representations described in the standard. A natural place for those functions would be as methods on a Context object; perhaps IEEEContext should be a subclass of Context? (OTOH, the struct module is another possible place for such functionality.) I'll think about this. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2010-05-22 22:21:39 | mark.dickinson | set | messages: + msg106325 |
| 2010-05-22 12:09:12 | mark.dickinson | set | nosy:
rhettinger, facundobatista, mark.dickinson, skrah type: enhancement components: + Library (Lib) stage: needs patch |
| 2010-05-22 12:07:53 | skrah | set | messages: + msg106303 |
| 2010-05-22 11:29:40 | mark.dickinson | set | messages: + msg106297 |
| 2010-05-22 11:24:03 | skrah | set | messages: + msg106296 |
| 2010-05-22 10:28:31 | mark.dickinson | create | |
