1

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.

Community
  • 1
  • 1
Alain
  • 26,663
  • 20
  • 114
  • 184
  • 1
    The more I read about this, the more it seem like the answer is that they decided: "this is too hard, let's not do it." Well tough, Microsoft. It's been in the IEEE standard for float/double since the beginning. Get your act together. – Alain May 16 '12 at 20:23

1 Answers1

2

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.

Samy Arous
  • 6,794
  • 13
  • 20
  • This would result in hundreds of little hacks all over the code and in our calculations. One of which is that we take advantage of the fact that `(Double.Infinity).ToString() == "Infinity"`, which is exactly what we want to display. `(Double.MaxValue).ToString()` would display `"1.7976931348623157E+308"`, so we'd get into having to write special converters and everything for every different case where controls are displaying double values. The ideal solution should happen at the data-service level, which is highly obfuscated since it's mostly built in `System.ServiceModel` stuff. – Alain May 16 '12 at 20:26
  • 2
    You will just need to convert it back when you get the values from the database (at the Model layer). This should minimize the amount of hacks. Unless you have multiple tables with this kind of values. – Samy Arous May 16 '12 at 20:29
  • I'm afraid this is the easier, unless someone come up with a SQL type which handle infinity. All other solution will imply modification either at the database structure or at the data-service level. – Samy Arous May 16 '12 at 20:43
  • Accepted, but having to use Double.MaxValue as a placeholder for Infinity is a gigantic hack that no one should have to put up with. The IEEE standard is what it is for a reason. I don't see why Microsoft won't just support it. – Alain May 24 '12 at 04:06