Skip to content
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

Overflow safety in duration unit classes #4

Closed
erikc5000 opened this issue Oct 25, 2019 · 0 comments · Fixed by #15
Closed

Overflow safety in duration unit classes #4

erikc5000 opened this issue Oct 25, 2019 · 0 comments · Fixed by #15
Labels
design Design issue/question

Comments

@erikc5000
Copy link
Owner

For the most part, Island Time detects and throws an exception on overflow, like java.time does. The unit classes are a bit inconsistent in that they aren't overflow safe by default.

Consider IntHours:

val totalHours = Int.MAX.hours + 1.hours // overflow
val minutes = Int.MAX.hours.inMinutes // overflow
val minutes2 = Int.MAX.hours.inMinutesExact() // exception

Internally, we have plusExact and minusExact infix functions to do overflow safe math. The question is whether or not these should be the default and instead, require a plusWithOverflow, minusWithOverflow, or inMinutesWithOverflow. I'm leaning "yes", but curious to hear if others have an opinion on this.

On native, it seems like LLVM's UBSan could be used to detect overflow during debug as a possible alternative, though not sure if enabling it is possible with Kotlin Native. Doesn't help with JVM though, obviously.

@erikc5000 erikc5000 added the design Design issue/question label Oct 25, 2019
@erikc5000 erikc5000 changed the title Overflow safety in unit classes Overflow safety in duration unit classes Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design issue/question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant