-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
I do not know who invented this, but look:
C# – Characteristics of the floating-point types
| C# type/keyword | Approximate range | Precision | Size | .NET type |
|---|---|---|---|---|
| float | ±1.5 x 10−45 to ±3.4 x 1038 | ~6-9 digits | 4 bytes | System.Single |
| double | ±5.0 × 10−324 to ±1.7 × 10308 | ~15-17 digits | 8 bytes | System.Double |
and now look at what F# has:
| Type | .NET type | Description | Example |
|---|---|---|---|
| float, double | Double | A 64-bit floating point type. | 1.0 |
| float32, single | Single | A 32-bit floating point type. | 1.0f |
So:
- C#
floatmaps to F#float32(orsingle) and - F#
floatmaps to C#double. 🤯
This is crazy and can cause lots of troubles.
Now, I can see the RowReader follows this and row.float maps to F# float32 instead of float a.k.a double.
/// Gets the value of the specified column as a `System.Single` object.
member this.float(column: string) : float32 =
this.fieldValue(column)
The problem is, the change could cause even more harm than good at this point, but I would recommend:
- make
RowReader'sfloatdeprecated (with explanation that the name is ambiguous) - use the
singleand maybe an aliasfloat32to describe 32-bit floating point conversion
With this change, we would avoid the contaminated float and also make the issue more expressive for those who are not aware of the trap. What would you say?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels