[quoted text, click to view] "TargetedConvergence@newsgroup.nospam" wrote:
> I am writing an engineering solution on top of Office and SQL Server.
> Dealing with IEEE double-precision floating point is always a pain,
> even with software tools that support it. It appears SQL Server does
> not even claim to support it. Exhaustive searching has not turned up
> some basic answers... experimentation can only say so much... please
> help:
>
> 1) Can I reliably save and retrieve a C# double from a SQL Server
> float? Tests work okay so far.
> 2) Can I reliably save and retrieve Double.PositiveInfinity and
> Double.Negative Infinity from a SQL Server float? Again, tests have
> worked... but can I count on it?
> 3) Can I reliably save and retrieve Double.NaN from a SQL Server float
> column?
> 4) Can I reliably search on a C# double value within a SQL Server float
> (assuming I am indeed searching on exactly the double value that I
> saved into the field)?
> 5) Can I reliably search for a Double.PositiveInfinity within a SQL
> Server float column?
> 6) Can I search WHERE Double.NegativeInfinity < float and float <
> Double.PositiveInfinity?
> 7) Is there any way to search / WHERE on Double.NaN (given NaN == NaN
> returns false, I'd need an IsNaN test in the WHERE clause)??
>
> If not, what's the best way to save double-precision IEEE floating
> point values in a SQL Server database?
> Consume the largest and two smallest values in the range specified by
> SQL Server and dub them +oo, -oo, and NaN, and convert them going in
> and coming out? (Ick.)
>
> Thanks!!
According to BOL under the entry for the float data type, float[n] follows
the SQL-92 standard where n is 1-53. And then the article titled "Using
decimal, float, and real Data", BOL states...
<quote>
The float and real data types are known as approximate data types. The
behavior of float and real follows the IEEE 754 specification on approximate
numeric data types
</quote>
....
<quote>
The IEEE 754 specification provides four rounding modes: round to nearest,
round up, round down, and round to zero. Microsoft SQL Serve⢠uses round
up
</quote>
I have no idea about your Nan and infinity in SQL queries, but I would
assume (regarding question #4) that you would use SQL similar to the
canonical way you compare FP's in procedural languages...
SELECT blah
WHERE fld
BETWEN @target - @precesion
AND
@target + @precision
Craig