Proposal: Floats with Ranges #6972
-
Here is my language idea proposal. It's called "Floats with Ranges". Introduction Another example: Proposal
The type of z will be determined before compilation: The type of w will be: We can specify multiple pairs e.g It is simple for the compiler to convert a domain to a range for many math functions including the usual arithmetic operators * + / -, square roots, trig functions, exponentials. Mostly you would not calculate the ranges yourself, you would use the var keyword. Or:
Or by hovering over the ? it would show the range. WHY OH WHY? This feature is an example of "Dependent Types" while not going the full way with dependent types but just taking a small part that is simple to implement. Also it's quite fun and interesting. Any Issues?
Now usually the type for z would be float<0,2> but in actual fact we know that the real range is float<0.9999,1.00001> for example because there is a correlation between the values. (All variables are assumed to be uncorrelated for easier calculation) So sometimes the true range will be less than the derived range. I don't think there is any way round this nor do I think this takes away from the usefulness of the proposal. Although in this specific case, a good compiler could probably work this out quite easily! (Really the above example is a fault of the programmer for not knowing the sin^2+cos^2 formula and simplifying it.) Another issue I haven't got a good language design for how one would do inclusive and exclusive ranges e.g. 2<x<5 vs 2<=x<=5. And we would need a good language design for ±Infinity at the ends of open ranges. In mathematics these range would be expressed as Casting
or automatic casting with:
For example if Helper functions Future enhancements Other Uses Workflow Conclusion |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 25 replies
-
See: #413 |
Beta Was this translation helpful? Give feedback.
-
Such as? |
Beta Was this translation helpful? Give feedback.
-
It's worth noting that many of the examples given are not "invalid inputs". That is, they do not cause the callee to They simply result in |
Beta Was this translation helpful? Give feedback.
Such as?