-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric types documentation and rough corners #2582
Comments
This is adding a float and an integer. Automatic conversions, as found in C and Java, often hide complexities. Do we really want to convert the integer into a float and then calculate a result, or would we prefer to convert the float into an integer and calculate an integer result? I think that it is best to force the programmer to make conversions explicit, as such conversions can change the affected values (due to the imprecision of a float). I'm personally in favor of providing, by default, an unbounded rational arithmetic. In other words, |
without some automatic conversion the "Numeric" type is rather dangerous. Consider
I agree an unbounded rational would be a very nice default. What do you think about automatic conversion - cases like taking sqrt() of such a rational? Also curious about things like is |
sqrt() is not a rational function. One would have to first convert a rational to a float, double, or some other approximate fixed-bit representation to apply functions such as sqrt(), sin(), cos(), etc. As for fixed-bit integers (int16, int32), they would need explicit conversions (sign-extend, 0-extend, or truncate) before being added together (using modulo arithmetic, of course). |
some difficult cases in the language need explanation, http://nitlanguage.org/manual/basic_type.html leaves much open.
print 1000*1000*1000
results in-73741824
on a 32bit system - this will be surprising for many programmers. I see 8,16,32 bit integers but nothing like bignums or 64bit integers?works as expected, whereas
gives an error. Is that intended? Is there some clever trick to achieve behaviour similar to that of most other languages?
1.0/0.0
and1/0
are handled differently. This is so in most other languages but does it make much sense? In a typed language a numeric expression returning a "not-a-number" value is a paradox and mabye #2314 could go.The text was updated successfully, but these errors were encountered: