 |
|
SQL Server Tips by Burleson |
Real and float
Real is a floating point numeric value with valid values –3.40E + 38
through -1.18E - 38, 0 and 1.18E - 38 through 3.40E + 38.
Float has valid values - 1.79E + 308 through -2.23E - 308, 0 and
2.23E -308 through 1.79E + 308.
The following example shows how a real value is stored using 32 bit
IEEE single-precision:
DECLARE @r real
SET @r=12345.67
SELECT @r, DATALENGTH(@r)
SELECT CAST(@r as binary(4))
12345.67 4
0x4640E6AE
Converting 4640E6AE to binary:
0 10001100 10000001110011010101110
S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF
0 1 8 9 31
S is the sign of the mantissa, E the exponent and F is the decimal
part of the mantissa.
S=0, E=140, F=81CD5C =>
1.F=1.81CD5C=1.50703979
Using the IEEE formula:
V=(-1)^S*2^(E-127)*(1.F)=(-1)^0*2^(140-127)*(1.50703979)=1*8192*1.50703979=12345.66995968=12345.67
The above book excerpt is from:
Super SQL
Server Systems
Turbocharge Database Performance with C++ External Procedures
ISBN:
0-9761573-2-2
Joseph Gama, P. J. Naughter
http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm |