Scala - Sum of positive Ints being negative - Overflow Exception? -


i had hard time finding bug being caused due large sum of positive ints being greater integer.max_value.

my question is: why:

val a:int = integer.max_value + 2 

-> = -2147483648 returns negative number, opposed giving overflow exception doing:

val b:int =999999999999999999 

-> error: integer number large

why not throwing exception standard?

adding checks costs performance , code rely on how overflows work.

if don't want overflow java 8 has solution:

math.addexact(left, right); 

https://docs.oracle.com/javase/8/docs/api/java/lang/math.html#addexact-int-int-


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -