-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDoubleProperties.scala
More file actions
42 lines (34 loc) · 964 Bytes
/
Copy pathDoubleProperties.scala
File metadata and controls
42 lines (34 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package doubleOperations
import utils.InputException
import utils.ExceptionMessages.ZeroInput
import utils.MathConstants.pi
/**
* Contains functions, affecting double properties.
*
* Purity project by Daniil Tekunov.
*/
class DoubleProperties(val firstDouble: Double) {
import DoubleProperties._
/**
* Returns the number, inversed via 1
*/
def inverse: Double = firstDouble match {
case 0 => throw new InputException("\"inverse\" " + ZeroInput)
case _ => 1 / firstDouble
}
/**
* Returns square of a Double
*/
def sqrDouble: Double = firstDouble * firstDouble
/**
* Returns absolute value of a Double
*/
def abs: Double = if (firstDouble < 0) -firstDouble else firstDouble
/**
* Returns double, converted to degrees
*/
def toDegrees: Double = firstDouble * 180.0 / pi
}
object DoubleProperties {
implicit def doubleToLocalProps(a: Double): DoubleProperties = new DoubleProperties(a)
}