Reputation: 27220
Clearly it's not quite true that SQL floats are the same as C# Doubles, as they can't hold values of Infinity.
I have a very straightforward mathematical model that deals with probabilities and return periods.
When
Double Probability = 0d
,
then by definition:
Double ReturnPeriod = Double.PositiveInfinity
When these properties are mapped to float parameters for an Insert command, I get an error at the DataService level as I try to execute the procedure:
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 134 ("@RETURNPERIOD"): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
How can I resolve this? I don't want to resort to anything absurd like changing the schema to store a string representation of the ReturnPeriods, or to add a secondary column for every single float to store whether it's +Inf, -Inf, or NaN.
Old 2006 posts like this one aren't really helping me out.
Upvotes: 1
Views: 2938
Reputation: 6814
I think what is meant when they say SQL floats are equivalent to Double, is that their representation is similar (using mantis and exponent and 64bits encoding).
I would suggest using Double.MaxValue as positive infinity and Double.MinValue as negative infinity. I doubt that you will get to use those values in your model.
Upvotes: 2