-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
[Suggestion] An exercise about numeric limits in Go #1109
Comments
As you probably know, all the exercises get their genesis from the exercises in problem-specifications. Do you have any specific ideas for an exercise related to numeric limits? We can begin the discussion here a bit, and then you could submit a suggested exercise to the problem-specifications. Any new exercise in problem-specifications should be very language agnostic, naturally. |
Hi @leenipper, IMO, knowing what computer can realistically represents is usually a good thing (especially when working with money & high-precision calculations). There are 2 parts: general way numbers are handled by computer and language-specific quirks. For the general stuff, how about an exercises on evaluating a user-defined expressions. For example, if we have: func EvalInt(expr string, map[string]int variables) int { ... }
// EvalInt("x + y", map[string]int{"x":1, "y":2}) -> 3
func EvalFloat64(expr string, map[string]float64 variables) { ... }
// EvalFloat64("x/2", map[string]float64{"x":4.0}) -> 2.0 we can introduce a few concepts: userExpr := "x + y"
variables := map[string]int{
"x": math.MaxInt32,
"y": math.MaxInt32,
}
result := EvalInt(userExpr, variables) // -> -2, due to integer overflow userExpr := "x/2"
variables := map[string]float64{
"x": math.SmallestNonzeroFloat64,
}
result := EvalFloat64(userExpr, variables) // -> 0, due to floating point underflow For language-specific part, I think an interesting exercise is to implement the Round() function (Go 1.10). Go's approach to this is different from some other languages (say Javascript), so it might be worth knowing. |
Closing this as it wasn't picked up in 3 years. In the v3 system, numeric limits are more a topic for the about.md file of some concept. |
Do we have any exercise that deals with the numeric limits of integer/floating point types in Go (e.g:
int
,int32
,int64
,float32
,float64
, etc) ?I have been doing a few math-based exercises, e.g: difference-of-squares, space-age, etc and haven't seen things like overflow, underflow get touched.
IMO, this might make for an interesting intermediate/advanced exercise, especially for those who will use Go professionally.
wdyt?
The text was updated successfully, but these errors were encountered: