Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in math.ceil by returning integral instead of float (fixes go…
…ogle#372) (google#373) * Fix bug in math.ceil by returning integral instead of float Python's math.ceil function always returns a value's ceiling as an integral, as can be seen in https://docs.python.org/3/library/math.html#math.ceil. The previous iteration of Starlark's math.ceil, however, would always return a float, as a result of being wrapped in newUnaryBuiltin. Since ceil is different from the other wrapped methods, as described above, separate it in its own function. It is worth noting that Python's math.ceil will also not accept non-finite values, such as nan, +inf, -inf and will return custom error messages for nan and infinities. These are also handled in the new ceil function. Finally, tests are incorporated in testdata/math.star to reflect the changes described above. * Move ceil function signature to one line * Prevent result of ceil from being lossy and abstract errors Unnecessary conversions were occuring due to immediately wrapping any input to ceil as a floatOrInt. By changing the expected input to accept a starlark Value, an Int type can be returned immediately. Also, MakeInt64 being called on the result of a float input could result in the conversion of the result to be lossy. This is handled by abstracting the conversion with NumberToInt. NumberToInt also returns the exact error messages that were included previously, so it is not required to rewrite them. * Add test for float value larger than int64 * Fix bugs with floor function returning floats The bugs that affected Starlark's math.ceil also affect math.floor. Therefore, a new floor function is introduced that handles those bugs. Note floor is similar to ceil except that it calls Go's Floor instead of Ceil. * Add tests to floor that represent fixes * Make float return one line * Make minor refactorings: join lines * Make minor refactorings: remove unnecessary comments * Derive float args for ceil and floor * Use bit shifting and same pattern for floor, ceil big float test
- Loading branch information