Package: MATH

MATH

nameinstructionbranchcomplexitylinemethod
MATH()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
acos(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
asin(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
atan(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
cos(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
cot(Value)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
exp(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
fac(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
factorial(long)
M: 13 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
ln(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
log(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
pi_f()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
rand(Value)
M: 31 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
sin(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
sqrt(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
srand2(Value)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
tan(Value)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008, 2009 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: // This must be in the default package to work with VDMJ's native delegation.
25:
26: import java.util.Random;
27:
28: import org.overture.interpreter.runtime.ValueException;
29: import org.overture.interpreter.values.IntegerValue;
30: import org.overture.interpreter.values.NaturalOneValue;
31: import org.overture.interpreter.values.RealValue;
32: import org.overture.interpreter.values.Value;
33:
34: public class MATH
35: {
36:         private static Random random = new Random();
37:         private static long seed = 0;
38:
39:         public static Value sin(Value arg) throws ValueException, Exception
40:         {
41:                 return new RealValue(Math.sin(arg.realValue(null)));
42:         }
43:
44:         public static Value cos(Value arg) throws ValueException, Exception
45:         {
46:                 return new RealValue(Math.cos(arg.realValue(null)));
47:         }
48:
49:         public static Value tan(Value arg) throws ValueException, Exception
50:         {
51:                 return new RealValue(Math.tan(arg.realValue(null)));
52:         }
53:
54:         public static Value cot(Value arg) throws ValueException, Exception
55:         {
56:                 return new RealValue(1 / Math.tan(arg.realValue(null)));
57:         }
58:
59:         public static Value asin(Value arg) throws ValueException, Exception
60:         {
61:                 return new RealValue(Math.asin(arg.realValue(null)));
62:         }
63:
64:         public static Value acos(Value arg) throws ValueException, Exception
65:         {
66:                 return new RealValue(Math.acos(arg.realValue(null)));
67:         }
68:
69:         public static Value atan(Value arg) throws ValueException, Exception
70:         {
71:                 return new RealValue(Math.atan(arg.realValue(null)));
72:         }
73:
74:         public static Value sqrt(Value arg) throws ValueException, Exception
75:         {
76:                 return new RealValue(Math.sqrt(arg.realValue(null)));
77:         }
78:
79:         public static Value pi_f() throws Exception
80:         {
81:                 return new RealValue(Math.PI);
82:         }
83:
84:         public static Value rand(Value arg) throws ValueException
85:         {
86:                 long lv = arg.intValue(null);
87:
88:•                if (seed == -1)
89:                 {
90:                         return new IntegerValue(lv);
91:•                } else if (lv == 0)
92:                 {
93:                         return new IntegerValue(0);
94:                 } else
95:                 {
96:                         return new IntegerValue(Math.abs(random.nextLong() % lv));
97:                 }
98:         }
99:
100:         public static Value srand2(Value arg) throws ValueException
101:         {
102:                 seed = arg.intValue(null);
103:                 random.setSeed(seed);
104:                 return new IntegerValue(seed);
105:         }
106:
107:         public static Value exp(Value arg) throws ValueException, Exception
108:         {
109:                 return new RealValue(Math.exp(arg.realValue(null)));
110:         }
111:
112:         public static Value ln(Value arg) throws ValueException, Exception
113:         {
114:                 return new RealValue(Math.log(arg.realValue(null)));
115:         }
116:
117:         public static Value log(Value arg) throws ValueException, Exception
118:         {
119:                 return new RealValue(Math.log10(arg.realValue(null)));
120:         }
121:
122:         public static Value fac(Value arg) throws ValueException, Exception
123:         {
124:                 return new NaturalOneValue(factorial(arg.natValue(null)));
125:         }
126:
127:         private static long factorial(long n)
128:         {
129:•                return n < 1 ? 1 : n * factorial(n - 1);
130:         }
131: }