/**
* Performs overflow checking for Int/Long operations.
*
* If no errors are detected, the expected result will be
* returned. If an error is detected, an ArithmeticOverflowException
* will be thrown.
*/
def checked[A](n: A): A = macro checkedImpl[A]
def checkedImpl[A: c.WeakTypeTag](c: Context)(n: c.Expr[A]): c.Expr[A] = {
import c.universe._
tryOrElseImpl[A](c)(n)(c.Expr[A](q"throw new spire.macros.ArithmeticOverflowException()"))
}
Could you please give an example of how to use `checked`? Naively, I'm also curious if this exception gets thrown at compile-time or run-time.
But it's not possible (or perhaps it's quite hard) to write a macro that performs an overflow check for String#toDouble, is that true?