internal number representation
|
10-05-2016, 06:25 AM
Post: #1
|
|||
|
|||
internal number representation
Hello all,
I still have some question about the internal representation of real numbers in the Prime. there is (in BCD): 1 nibble for the sign (4 bits) 12 nibbles for the mantissa 3 nibbles for the signed exponent How is the sign represented within the 4 sign bits? What can these 4 bits represent (+ infinity, -infinity, ...) and how will it be done? How is the signed exponent represented within the 3 BCD nibbles? Is it shifted by 499, so -499 will be 000, 0 will be 499 and +499 will be 998? Is it possible to have a detailed description of the significance of the various bits? Is there a way to see the internal binary representation of a real number (something like casting a real to a longint)? Thank you very much for the help, I want to explain it to my students, but I'm not sure about how it will be done and don't want to expose it wrong. Reto |
|||
10-05-2016, 03:42 PM
Post: #2
|
|||
|
|||
RE: internal number representation
You can directly look at the binary structure of any THPObj (as we call them) by storing the item using AFiles. AFilesB will allow direct return of the item as byte arrays. Another post from cyrille (coincidentally near the same time as your question) talks a bit about the header on the front of the objects.
Quote:Actually, what you are doing when you do: AFiles("num"):=0 followed by AFilesB("num",0,16) returns the full byte representation of the file. In your case, skip the first 8 and look at the last 8 bytes. That is the real number encoding in BCD. I'm also including some comments from a header file which should be helpful. Code: * see the HP_Real structure to see how reals are stored (sign, exponent, mantissa) Note that we really only use the e499 version from the end user perspective. Other longer use is only internal and even then we don't use the extended exponent capacity at all. Also, when saving to disk the reals get packed to save space. Hence, the return from AFiles only takes 8 bytes for a single real. "Packing" basically means that there is only space for the 12digit BCD, 3 byte exponent, and 1 byte sign vs the 15 digit bcd, 4 byte exponent, and 1 byte sign of the "unpacked" real. If you're interested, the code to do the packing looks like this: Code: PackedHP_Real fPack(HP_Real const *a) Heres is more comments about the unpacked HP_Real. Code: /// A HP_Real is a group of 3 elements. A Sign (which is also can carry information on Really, the primary difference between the HP48 series encoding of reals and the newer encoding is that instead of encoding the exponent as BCD, that is encoded as a plain integer value while the mantissa is still kept in BCD. Perhaps someone can link to or find a good reference where the 48 real number encoding is explained??? From this explanation, you can probably pretty easily figure out how a complex is encoded (2 paired reals with a different header), a matrix (size info, followed by reals), a complex matrix, etc. TW Although I work for HP, the views and opinions I post here are my own. |
|||
10-05-2016, 09:27 PM
Post: #3
|
|||
|
|||
RE: internal number representation
Thank you Tim !
Your informations were very useful. The exponent is a signed binary integer, not BCD. Reto |
|||
10-07-2016, 01:05 AM
Post: #4
|
|||
|
|||
RE: internal number representation
On the HP 48, the sign nibble is encoded with 0 meaning positive and 9 meaning negative.
The 3 nibble of the exponent are encoded in BCD, but if the value is negative, then it's encoded as 1000-ABS(exponent). Put another way, if value in the exponent nibbles is more than 499, then take the value, subtract it from 1000 , negate it and that's the value. For example, if the exponent nibbles contain 600, then actual exponent is -(1000-600) = -400. See pages 104-105 here: http://www.hpcalc.org/details/1693 |
|||
10-07-2016, 07:30 AM
Post: #5
|
|||
|
|||
RE: internal number representation
Thank you very much David!
A very useful document |
|||
10-08-2016, 08:37 PM
Post: #6
|
|||
|
|||
RE: internal number representation
Two key differences between HP_Real and IEEE 754/854 formats is that HP_Real doesn't have signed zeroes and doesn't have denormalized numbers (no gradual underflow).
The 15-digit HP_Real can be used for internal calculations: to provide guard digits and to simulate gradual underflow of 12-digit HP_Real values, among other uses. The greater exponent range allows things like more direct calculation of sqrt(x^2+y^2) — by using 15-digit HP_Reals for the operations even though x and y are 12-digit HP_Real values. The two systems also have different rounding behaviours. NaNs are also treated differently (especially when used via PPL). |
|||
10-10-2016, 10:05 AM
Post: #7
|
|||
|
|||
RE: internal number representation
Hello,
The math library used in Prime was originally a pure rewrite of the HP 48 assembly, following the exact same format... But as time went on and backward compatibility was deemed less and less important, the 2 formats have started to drift in order to simplify things on non BCD microprocessors. Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 3 Guest(s)