This is slightly adapted from an old UniVerse Technical Bulletin (about WIDE0)

UniVerse follows the IEEE format for double precision floating point numbers, and uses 
this for any datum that has the NUMBER data type.  (Prior to release 6 this was the 
only numeric data type in UniVerse.)  Under this convention:
7       the leftmost bit is reserved as the sign bit
7       the next eleven bits are used for the exponent, which is biased by the 
constant value 1023
7       the remaining 52 bits are used to store the mantissa of the number

Consider the decimal number 49.75.  The binary representation of 49 is 110001 (that 
is, 32 + 16 + 1).  The fractional part comprises one half and one quarter, so the 
whole number in binary would be 110001^11
Since the mantissa is always stored as a fraction, we must move the binary point six 
places to the left to make the significant bits of the mantissa fractional (this would 
be ^11000111).  Storing the mantissa as a fraction allows an arbitrary number of zero 
trailing bits.

The floating point system provides for an extra bit of precision by always shifting 
one place less than needed, since the high order bit is always 1 and therefore need 
not be stored.  Our 49.75 would now be ((1)^1000111).
Shifting the binary point five places to the left means that we must add five to the 
exponent (already 1023 from the bias), so the exponent value becomes 1028 (or 
10000000100 in binary).  The final floating point number becomes:
010000000100100011100000000000000000000000000000000000000000000

Obviously working in binary is tedious for humans, so we usually represent numbers in 
hexadecimal (which maps directly onto binary).  The above number can be represented as 
0x4048E00000000000.  The “0x” indicates that what follows is a hexadecimal 
number.  Each digit represents four bits.

When comparing two numbers UniVerse examines the exponent of the difference between 
them.  If the exponent of the difference indicates that the difference is a very small 
number, then UniVerse concludes that the numbers are equal.

As shipped, UniVerse assumes that any difference smaller than approximately 2.91E-11 
is equal to zero.  This provides precision somewhat greater than the ten decimal 
digits advertised by UniVerse BASIC programs.  [The maximum value for PRECISION is, in 
fact, 14 (unless changed by the configurable parameter EXACTNUMERIC (introduced in 
release 9.6), which allows up to 57).  This means that BASIC programs can output up to 
14 significant digits when converting a number into a string (for example for output). 
 However, all calculations are performed at the full precision of which the arithmetic 
logic unit in the CPU is capable.]

The default “wide zero” mask for IEEE compliant machines is 0x3dc00000.  
If your default mask is not 0x3dc00000 then your machine is not IEEE compliant (or has 
been changed).

The configurable parameter WIDEZERO allows this mask to be changed.  The value in the 
configuration file is expressed in hexadecimal notation (the “0x” prefix 
is required) and represents the high order 32 bits of the wide zero value.
In the following example, the binary representation of 49.75 shown earlier is compared 
with the default WIDEZERO setting.  This example shows that the WIDEZERO setting masks 
only bits in the exponent.
010000000100100011100000000000000000000000000000000000000000000
0011110111000000000000000000000    is the binary form of 0x3dc00000, the default 
setting for WIDEZERO.

(The effect of the WIDEZERO tuneable parameter can be disabled in BASIC programs 
through use of the $OPTIONS –WIDE.IF compiler directive.)
-------
u2-users mailing list
[EMAIL PROTECTED]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to