Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala
math
difference
communitycreator

What is subtractExact(x: Long, y: Long) in Scala?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

subtractExact(x: Long, y: Long) is a function in the math package of Scala. The function returns the difference of the numbers passed in as arguments.

Syntax

def subtractExact(x: Long, y: Long): Long

Parameters

The function takes in two parameters, x and y. The parameters are of the Long type.

Return value

The function returns the value of x - y.

The function throws ArithmeticException if the return value overflows the Long.

Code

object MainObject {
def main(args: Array[String]) {
var x : Long = 32;
var y : Long = 10;
println("Math.subtractExact(x, y) = " + Math.subtractExact(x, y));
}
}

RELATED TAGS

scala
math
difference
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring