1

Consider the following generator method:

IEnumerable<double> Get(long baseValue, double offset)
{
  double value = baseValue;
  while (true)
  {
    value += offset;
    yield return value;
  }
}

AFAIK, double and long have the same size (byte wise), and double uses some of these bytes to represent floating point precision.

Does this mean that given a big enough 'baseValue' parameter, The above method will overflow, causing some loss to the range of values I can represent?

CLARIFICATION:

Essentially, the 'baseValue' parameter represents some time stamp in milliseconds, and the double represents a calculated offset in milliseconds, which must be a double due to domain constraints.

Both base and n items from the sequence are sent over the wire to non .NET environments, so I must send primitive values, avoiding any .NET types.

Eyal Perry
  • 2,255
  • 18
  • 26

0 Answers0