root / trunk / compiler / ooasCompiler / src / org / momut / ooas / math / SaturatedDoubleOperations.java @ 7
1 |
/**
|
---|---|
2 |
*
|
3 |
* OOAS Compiler
|
4 |
*
|
5 |
* Copyright 2015, AIT Austrian Institute of Technology.
|
6 |
* This code is based on the C# Version of the OOAS Compiler, which is
|
7 |
* copyright 2015 by the Institute of Software Technology, Graz University
|
8 |
* of Technology with portions copyright by the AIT Austrian Institute of
|
9 |
* Technology. All rights reserved.
|
10 |
*
|
11 |
* SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
|
12 |
*
|
13 |
* If you modify the file please update the list of contributors below to in-
|
14 |
* clude your name. Please also stick to the coding convention of using TABs
|
15 |
* to do the basic (block-level) indentation and spaces for anything after
|
16 |
* that. (Enable the display of special chars and it should be pretty obvious
|
17 |
* what this means.) Also, remove all trailing whitespace.
|
18 |
*
|
19 |
* Contributors:
|
20 |
* Willibald Krenn (AIT)
|
21 |
* Stephan Zimmerer (AIT)
|
22 |
* Markus Demetz (AIT)
|
23 |
* Christoph Czurda (AIT)
|
24 |
*
|
25 |
*/
|
26 |
|
27 |
|
28 |
package org.momut.ooas.math; |
29 |
|
30 |
|
31 |
public final class SaturatedDoubleOperations extends Operations<Double>{ |
32 |
public static final class SatDoubleBasicOps extends BasicOps<Double> { |
33 |
private static double checkRange(double aValue) |
34 |
{ |
35 |
if (aValue == Double.POSITIVE_INFINITY) |
36 |
return Double.MAX_VALUE; |
37 |
else if (aValue == Double.NEGATIVE_INFINITY) |
38 |
return Double.MIN_VALUE; |
39 |
else
|
40 |
return aValue;
|
41 |
} |
42 |
|
43 |
@Override
|
44 |
public Double unMinus(Double input) { |
45 |
return checkRange(-input);
|
46 |
} |
47 |
@Override
|
48 |
public Double minus(Double inputA, Double inputB) { |
49 |
return checkRange(inputA - inputB);
|
50 |
} |
51 |
@Override
|
52 |
public Double plus(Double inputA, Double inputB) { |
53 |
return checkRange(inputA + inputB);
|
54 |
} |
55 |
@Override
|
56 |
public Double div(Double inputA, Double inputB) { |
57 |
return checkRange(inputA / inputB);
|
58 |
} |
59 |
@Override
|
60 |
public Double pow(Double inputA, Double inputB) { |
61 |
return checkRange(Math.pow(inputA, inputB)); |
62 |
} |
63 |
@Override
|
64 |
public Double prod(Double inputA, Double inputB) { |
65 |
return checkRange(inputA * inputB);
|
66 |
} |
67 |
@Override
|
68 |
public Double mod(Double inputA, Double inputB) { |
69 |
return checkRange(inputA % inputB);
|
70 |
} |
71 |
@Override
|
72 |
public boolean equal(Double inputA, Double inputB) {return inputA.equals(inputB);} |
73 |
@Override
|
74 |
public boolean smaller(Double inputA, Double inputB) {return inputA < inputB;} |
75 |
@Override
|
76 |
public boolean greater(Double inputA, Double inputB){return inputA > inputB;} |
77 |
@Override
|
78 |
public Double getDefaultValue() {return 0.0;} |
79 |
} |
80 |
|
81 |
public SaturatedDoubleOperations() {
|
82 |
super(new SatDoubleBasicOps()); |
83 |
} |
84 |
} |