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

Division and rational numbers #901

Closed
cxielarko opened this Issue Apr 19, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@cxielarko

cxielarko commented Apr 19, 2017

Are Integers intended to be compatible with a (hypothetical) rational type, and if so, how should division be handled? Under the current definition of division, either integers couldn't be treated as a subset of rationals, or there would need to be a separate operator for rational division.

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan

littledan Apr 19, 2017

Member

Under this proposal, division of integers always results in an Integer (or an exception for dividing by zero), based on round-towards-zero semantics. If we add a rational type later, the way to get at rational division would be to cast both arguments to a rational, and then divide.

It's understandable if this behavior and future interface is undesirable. One alternative here would be to throw in this proposal on all division, so that we can make it result in another type to express the exact answer in a future proposal. However, this choice would be an unfortunate missing feature as far as ergonomics, and it would block users who would use Integer to get at many machines' underlying int64 division hardware.

Member

littledan commented Apr 19, 2017

Under this proposal, division of integers always results in an Integer (or an exception for dividing by zero), based on round-towards-zero semantics. If we add a rational type later, the way to get at rational division would be to cast both arguments to a rational, and then divide.

It's understandable if this behavior and future interface is undesirable. One alternative here would be to throw in this proposal on all division, so that we can make it result in another type to express the exact answer in a future proposal. However, this choice would be an unfortunate missing feature as far as ergonomics, and it would block users who would use Integer to get at many machines' underlying int64 division hardware.

@ljharb

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Apr 19, 2017

Member

This question belongs in the proposal repo itself, not here on the spec repo.

Member

ljharb commented Apr 19, 2017

This question belongs in the proposal repo itself, not here on the spec repo.

@ljharb ljharb closed this Apr 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment