-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathAbstractFloatingPointFormulaManager.java
More file actions
620 lines (505 loc) · 22.4 KB
/
AbstractFloatingPointFormulaManager.java
File metadata and controls
620 lines (505 loc) · 22.4 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
// This file is part of JavaSMT,
// an API wrapper for a collection of SMT solvers:
// https://github.com/sosy-lab/java-smt
//
// SPDX-FileCopyrightText: 2026 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.sosy_lab.java_smt.basicimpl;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.sosy_lab.java_smt.basicimpl.AbstractFormulaManager.checkVariableName;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.sosy_lab.common.MoreStrings;
import org.sosy_lab.common.rationals.Rational;
import org.sosy_lab.java_smt.api.BitvectorFormula;
import org.sosy_lab.java_smt.api.BooleanFormula;
import org.sosy_lab.java_smt.api.FloatingPointFormula;
import org.sosy_lab.java_smt.api.FloatingPointFormulaManager;
import org.sosy_lab.java_smt.api.FloatingPointNumber.Sign;
import org.sosy_lab.java_smt.api.FloatingPointRoundingMode;
import org.sosy_lab.java_smt.api.FloatingPointRoundingModeFormula;
import org.sosy_lab.java_smt.api.Formula;
import org.sosy_lab.java_smt.api.FormulaType;
import org.sosy_lab.java_smt.api.FormulaType.BitvectorType;
import org.sosy_lab.java_smt.api.FormulaType.FloatingPointType;
/**
* Similar to the other Abstract*FormulaManager classes in this package, this class serves as a
* helper for implementing {@link FloatingPointFormulaManager}. It handles all the unwrapping and
* wrapping from and to the {@link Formula} instances, such that the concrete class needs to handle
* only its own internal types.
*
* <p>For {@link #multiply(FloatingPointFormula, FloatingPointFormula)}, and {@link
* #divide(FloatingPointFormula, FloatingPointFormula)} this class even offers an implementation
* based on UFs. Subclasses are supposed to override them if they can implement these operations
* more precisely (for example multiplication with constants should be supported by all solvers and
* implemented by all subclasses).
*/
@SuppressWarnings("ClassTypeParameterName")
public abstract class AbstractFloatingPointFormulaManager<TFormulaInfo, TType, TEnv, TFuncDecl>
extends AbstractBaseFormulaManager<TFormulaInfo, TType, TEnv, TFuncDecl>
implements FloatingPointFormulaManager {
private final Map<FloatingPointRoundingMode, TFormulaInfo> roundingModes;
private final AbstractBitvectorFormulaManager<TFormulaInfo, TType, TEnv, TFuncDecl> bvMgr;
protected AbstractFloatingPointFormulaManager(
FormulaCreator<TFormulaInfo, TType, TEnv, TFuncDecl> pCreator,
AbstractBitvectorFormulaManager<TFormulaInfo, TType, TEnv, TFuncDecl> pBvMgr) {
super(pCreator);
roundingModes = new HashMap<>();
bvMgr = pBvMgr;
}
protected abstract TFormulaInfo getDefaultRoundingMode();
protected abstract TFormulaInfo getRoundingModeImpl(
FloatingPointRoundingMode pFloatingPointRoundingMode);
private TFormulaInfo getRoundingMode(FloatingPointRoundingMode pFloatingPointRoundingMode) {
return roundingModes.computeIfAbsent(pFloatingPointRoundingMode, this::getRoundingModeImpl);
}
@Override
public FloatingPointRoundingModeFormula makeRoundingMode(
FloatingPointRoundingMode pRoundingMode) {
return getFormulaCreator().encapsulateRoundingMode(getRoundingMode(pRoundingMode));
}
@Override
public FloatingPointRoundingMode fromRoundingModeFormula(
FloatingPointRoundingModeFormula pRoundingModeFormula) {
return getFormulaCreator().getRoundingMode(extractInfo(pRoundingModeFormula));
}
/**
* Wraps a native floating-point term in a JavaSMT {@link FloatingPointFormula}. If the {@link
* FloatingPointType} of the term is not available, please use {@link
* AbstractFloatingPointFormulaManager#wrap(Object)}
*
* @param pTypeForAssertions the {@link FloatingPointType} used to create pTerm. This argument is
* only used to verify the exponent and mantissa sizes of pTerm.
*/
protected FloatingPointFormula wrap(
TFormulaInfo pTerm, @Nullable FloatingPointType pTypeForAssertions) {
FormulaType<?> type = getFormulaCreator().getFormulaType(pTerm);
// The type derived from the term in the creator is usually built from the exponent and
// mantissa sizes, hence comparing it to the type used to create the FP term checks that it
// was created correctly. (There are other tests checking FP type correctness)
if (pTypeForAssertions != null) {
checkArgument(
type.equals(pTypeForAssertions),
"Floating-Point formula %s type %s is not equal to expected type %s",
pTerm,
type,
pTypeForAssertions);
} else {
checkArgument(
type.isFloatingPointType(),
"Floating-Point formula %s has unexpected type: %s",
pTerm,
type);
}
return getFormulaCreator().encapsulateFloatingPoint(pTerm);
}
/**
* Wraps a native floating-point term in a JavaSMT {@link FloatingPointFormula}. Please use {@link
* AbstractFloatingPointFormulaManager#wrap(Object, FloatingPointType)} if the {@link
* FloatingPointType} of the term is available.
*/
protected FloatingPointFormula wrap(TFormulaInfo pTerm) {
return wrap(pTerm, null);
}
@Override
public FloatingPointFormula makeNumber(Rational n, FormulaType.FloatingPointType type) {
return wrap(makeNumberImpl(n.toString(), type, getDefaultRoundingMode()), type);
}
@Override
public FloatingPointFormula makeNumber(
Rational n, FloatingPointType type, FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(
makeNumberImpl(n.toString(), type, getRoundingMode(pFloatingPointRoundingMode)), type);
}
@Override
public FloatingPointFormula makeNumber(double n, FormulaType.FloatingPointType type) {
return wrap(makeNumberImpl(n, type, getDefaultRoundingMode()), type);
}
@Override
public FloatingPointFormula makeNumber(
double n, FloatingPointType type, FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(makeNumberImpl(n, type, getRoundingMode(pFloatingPointRoundingMode)), type);
}
protected abstract TFormulaInfo makeNumberImpl(
double n, FormulaType.FloatingPointType type, TFormulaInfo pFloatingPointRoundingMode);
@Override
public FloatingPointFormula makeNumber(BigDecimal n, FormulaType.FloatingPointType type) {
return wrap(makeNumberImpl(n, type, getDefaultRoundingMode()), type);
}
@Override
public FloatingPointFormula makeNumber(
BigDecimal n, FloatingPointType type, FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(makeNumberImpl(n, type, getRoundingMode(pFloatingPointRoundingMode)), type);
}
protected TFormulaInfo makeNumberImpl(
BigDecimal n, FormulaType.FloatingPointType type, TFormulaInfo pFloatingPointRoundingMode) {
return makeNumberImpl(n.toPlainString(), type, pFloatingPointRoundingMode);
}
@Override
public FloatingPointFormula makeNumber(String n, FormulaType.FloatingPointType type) {
return wrap(makeNumberImpl(n, type, getDefaultRoundingMode()), type);
}
@Override
public FloatingPointFormula makeNumber(
String n, FloatingPointType type, FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(makeNumberImpl(n, type, getRoundingMode(pFloatingPointRoundingMode)), type);
}
/** directly catch the most common special String constants. */
protected TFormulaInfo makeNumberImpl(
String n, FormulaType.FloatingPointType type, TFormulaInfo pFloatingPointRoundingMode) {
if (n.startsWith("+")) {
n = n.substring(1);
}
switch (n) {
case "NaN":
case "-NaN":
return makeNaNImpl(type);
case "Infinity":
return makePlusInfinityImpl(type);
case "-Infinity":
return makeMinusInfinityImpl(type);
default:
return makeNumberAndRound(n, type, pFloatingPointRoundingMode);
}
}
@Override
public FloatingPointFormula makeNumber(
BigInteger exponent, BigInteger mantissa, Sign sign, FloatingPointType type) {
return wrap(makeNumberImpl(exponent, mantissa, sign, type), type);
}
protected abstract TFormulaInfo makeNumberImpl(
BigInteger exponent, BigInteger mantissa, Sign sign, FloatingPointType type);
protected static boolean isNegativeZero(Double pN) {
checkNotNull(pN);
return Double.valueOf("-0.0").equals(pN);
}
/**
* Parses the provided string and converts it into a floating-point formula.
*
* <p>The input string must represent a valid finite floating-point number. Values such as NaN,
* Infinity, or -Infinity are not allowed and should be handled before calling this method.
*/
protected abstract TFormulaInfo makeNumberAndRound(
String pN, FloatingPointType pType, TFormulaInfo pFloatingPointRoundingMode);
@Override
public FloatingPointFormula makeVariable(String pVar, FormulaType.FloatingPointType pType) {
checkVariableName(pVar);
return wrap(makeVariableImpl(pVar, pType), pType);
}
protected abstract TFormulaInfo makeVariableImpl(
String pVar, FormulaType.FloatingPointType pType);
@Override
public FloatingPointFormula makePlusInfinity(FormulaType.FloatingPointType pType) {
return wrap(makePlusInfinityImpl(pType), pType);
}
protected abstract TFormulaInfo makePlusInfinityImpl(FormulaType.FloatingPointType pType);
@Override
public FloatingPointFormula makeMinusInfinity(FormulaType.FloatingPointType pType) {
return wrap(makeMinusInfinityImpl(pType), pType);
}
protected abstract TFormulaInfo makeMinusInfinityImpl(FormulaType.FloatingPointType pType);
@Override
public FloatingPointFormula makeNaN(FormulaType.FloatingPointType pType) {
return wrap(makeNaNImpl(pType), pType);
}
protected abstract TFormulaInfo makeNaNImpl(FormulaType.FloatingPointType pType);
@Override
public <T extends Formula> T castTo(
FloatingPointFormula pNumber, boolean pSigned, FormulaType<T> pTargetType) {
return getFormulaCreator()
.encapsulate(
pTargetType,
castToImpl(extractInfo(pNumber), pSigned, pTargetType, getDefaultRoundingMode()));
}
@Override
public <T extends Formula> T castTo(
FloatingPointFormula number,
boolean pSigned,
FormulaType<T> targetType,
FloatingPointRoundingMode pFloatingPointRoundingMode) {
return getFormulaCreator()
.encapsulate(
targetType,
castToImpl(
extractInfo(number),
pSigned,
targetType,
getRoundingMode(pFloatingPointRoundingMode)));
}
protected abstract TFormulaInfo castToImpl(
TFormulaInfo pNumber,
boolean pSigned,
FormulaType<?> pTargetType,
TFormulaInfo pRoundingMode);
@Override
public FloatingPointFormula castFrom(
Formula pNumber, boolean pSigned, FormulaType.FloatingPointType pTargetType) {
return wrap(
castFromImpl(extractInfo(pNumber), pSigned, pTargetType, getDefaultRoundingMode()),
pTargetType);
}
@Override
public FloatingPointFormula castFrom(
Formula number,
boolean signed,
FloatingPointType targetType,
FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(
castFromImpl(
extractInfo(number), signed, targetType, getRoundingMode(pFloatingPointRoundingMode)),
targetType);
}
protected abstract TFormulaInfo castFromImpl(
TFormulaInfo pNumber,
boolean pSigned,
FormulaType.FloatingPointType pTargetType,
TFormulaInfo pRoundingMode);
@Override
public FloatingPointFormula fromIeeeBitvector(
BitvectorFormula pNumber, FloatingPointType pTargetType) {
BitvectorType bvType = (BitvectorType) formulaCreator.getFormulaType(pNumber);
checkArgument(
bvType.getSize() == pTargetType.getTotalSize(),
MoreStrings.lazyString(
() ->
String.format(
"The total size %s of type %s has to match the size %s of type %s.",
pTargetType.getTotalSize(), pTargetType, bvType.getSize(), bvType)));
return wrap(fromIeeeBitvectorImpl(extractInfo(pNumber), pTargetType), pTargetType);
}
protected abstract TFormulaInfo fromIeeeBitvectorImpl(
TFormulaInfo pNumber, FloatingPointType pTargetType);
@Override
public BitvectorFormula toIeeeBitvector(FloatingPointFormula pNumber) {
return getFormulaCreator().encapsulateBitvector(toIeeeBitvectorImpl(extractInfo(pNumber)));
}
@SuppressWarnings("unused")
protected TFormulaInfo toIeeeBitvectorImpl(TFormulaInfo pNumber) {
throw new UnsupportedOperationException(
"The chosen solver does not support transforming "
+ "floating-point formulas to IEEE bitvectors natively");
}
@Override
public BooleanFormula toIeeeBitvector(
FloatingPointFormula fpNumber, BitvectorFormula bitvectorFormulaSetToBeEqualToFpNumber) {
FormulaType.FloatingPointType fpType =
(FloatingPointType) getFormulaCreator().getFormulaType(fpNumber);
checkArgument(
fpType.getTotalSize() == bvMgr.getLength(bitvectorFormulaSetToBeEqualToFpNumber),
"The size of the bitvector term %s is %s, but needs to be equal to the size of"
+ " the Floating-Point term %s with size %s",
bitvectorFormulaSetToBeEqualToFpNumber,
bvMgr.getLength(bitvectorFormulaSetToBeEqualToFpNumber),
fpNumber,
fpType.getTotalSize());
FloatingPointFormula fromIeeeBitvector =
fromIeeeBitvector(bitvectorFormulaSetToBeEqualToFpNumber, fpType);
// We use assignment(), as it allows a fp value to be NaN etc.
// Note: All fp.to_* functions are unspecified for NaN and infinity input values in the
// standard, what solvers return might be distinct.
return assignment(fromIeeeBitvector, fpNumber);
}
@Override
public FloatingPointFormula negate(FloatingPointFormula pNumber) {
TFormulaInfo param1 = extractInfo(pNumber);
return wrap(negate(param1));
}
protected abstract TFormulaInfo negate(TFormulaInfo pParam1);
@Override
public FloatingPointFormula abs(FloatingPointFormula pNumber) {
TFormulaInfo param1 = extractInfo(pNumber);
return wrap(abs(param1));
}
protected abstract TFormulaInfo abs(TFormulaInfo pParam1);
@Override
public FloatingPointFormula max(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
return wrap(max(extractInfo(pNumber1), extractInfo(pNumber2)));
}
protected abstract TFormulaInfo max(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public FloatingPointFormula min(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
return wrap(min(extractInfo(pNumber1), extractInfo(pNumber2)));
}
protected abstract TFormulaInfo min(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public FloatingPointFormula sqrt(FloatingPointFormula pNumber) {
return wrap(sqrt(extractInfo(pNumber), getDefaultRoundingMode()));
}
@Override
public FloatingPointFormula sqrt(
FloatingPointFormula number, FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(sqrt(extractInfo(number), getRoundingMode(pFloatingPointRoundingMode)));
}
protected abstract TFormulaInfo sqrt(TFormulaInfo pNumber, TFormulaInfo pRoundingMode);
@Override
public FloatingPointFormula add(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrap(add(param1, param2, getDefaultRoundingMode()));
}
@Override
public FloatingPointFormula add(
FloatingPointFormula number1,
FloatingPointFormula number2,
FloatingPointRoundingMode pFloatingPointRoundingMode) {
return wrap(
add(
extractInfo(number1),
extractInfo(number2),
getRoundingMode(pFloatingPointRoundingMode)));
}
protected abstract TFormulaInfo add(
TFormulaInfo pParam1, TFormulaInfo pParam2, TFormulaInfo pRoundingMode);
@Override
public FloatingPointFormula subtract(
FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrap(subtract(param1, param2, getDefaultRoundingMode()));
}
@Override
public FloatingPointFormula subtract(
FloatingPointFormula number1,
FloatingPointFormula number2,
FloatingPointRoundingMode pFloatingPointRoundingMode) {
TFormulaInfo param1 = extractInfo(number1);
TFormulaInfo param2 = extractInfo(number2);
return wrap(subtract(param1, param2, getRoundingMode(pFloatingPointRoundingMode)));
}
protected abstract TFormulaInfo subtract(
TFormulaInfo pParam1, TFormulaInfo pParam2, TFormulaInfo pFloatingPointRoundingMode);
@Override
public FloatingPointFormula divide(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrap(divide(param1, param2, getDefaultRoundingMode()));
}
@Override
public FloatingPointFormula divide(
FloatingPointFormula number1,
FloatingPointFormula number2,
FloatingPointRoundingMode pFloatingPointRoundingMode) {
TFormulaInfo param1 = extractInfo(number1);
TFormulaInfo param2 = extractInfo(number2);
return wrap(divide(param1, param2, getRoundingMode(pFloatingPointRoundingMode)));
}
protected abstract TFormulaInfo divide(
TFormulaInfo pParam1, TFormulaInfo pParam2, TFormulaInfo pFloatingPointRoundingMode);
@Override
public FloatingPointFormula multiply(
FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrap(multiply(param1, param2, getDefaultRoundingMode()));
}
@Override
public FloatingPointFormula multiply(
FloatingPointFormula number1,
FloatingPointFormula number2,
FloatingPointRoundingMode pFloatingPointRoundingMode) {
TFormulaInfo param1 = extractInfo(number1);
TFormulaInfo param2 = extractInfo(number2);
return wrap(multiply(param1, param2, getRoundingMode(pFloatingPointRoundingMode)));
}
protected abstract TFormulaInfo multiply(
TFormulaInfo pParam1, TFormulaInfo pParam2, TFormulaInfo pFloatingPointRoundingMode);
@Override
public FloatingPointFormula remainder(
FloatingPointFormula number1, FloatingPointFormula number2) {
return wrap(remainder(extractInfo(number1), extractInfo(number2)));
}
protected abstract TFormulaInfo remainder(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula assignment(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrapBool(assignment(param1, param2));
}
protected abstract TFormulaInfo assignment(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula equalWithFPSemantics(
FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrapBool(equalWithFPSemantics(param1, param2));
}
protected abstract TFormulaInfo equalWithFPSemantics(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula greaterThan(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrapBool(greaterThan(param1, param2));
}
protected abstract TFormulaInfo greaterThan(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula greaterOrEquals(
FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrapBool(greaterOrEquals(param1, param2));
}
protected abstract TFormulaInfo greaterOrEquals(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula lessThan(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrapBool(lessThan(param1, param2));
}
protected abstract TFormulaInfo lessThan(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula lessOrEquals(FloatingPointFormula pNumber1, FloatingPointFormula pNumber2) {
TFormulaInfo param1 = extractInfo(pNumber1);
TFormulaInfo param2 = extractInfo(pNumber2);
return wrapBool(lessOrEquals(param1, param2));
}
protected abstract TFormulaInfo lessOrEquals(TFormulaInfo pParam1, TFormulaInfo pParam2);
@Override
public BooleanFormula isNaN(FloatingPointFormula pNumber) {
return wrapBool(isNaN(extractInfo(pNumber)));
}
protected abstract TFormulaInfo isNaN(TFormulaInfo pParam);
@Override
public BooleanFormula isInfinity(FloatingPointFormula pNumber) {
return wrapBool(isInfinity(extractInfo(pNumber)));
}
protected abstract TFormulaInfo isInfinity(TFormulaInfo pParam);
@Override
public BooleanFormula isZero(FloatingPointFormula pNumber) {
return wrapBool(isZero(extractInfo(pNumber)));
}
protected abstract TFormulaInfo isZero(TFormulaInfo pParam);
@Override
public BooleanFormula isSubnormal(FloatingPointFormula pNumber) {
return wrapBool(isSubnormal(extractInfo(pNumber)));
}
protected abstract TFormulaInfo isSubnormal(TFormulaInfo pParam);
@Override
public BooleanFormula isNormal(FloatingPointFormula pNumber) {
return wrapBool(isNormal(extractInfo(pNumber)));
}
protected abstract TFormulaInfo isNormal(TFormulaInfo pParam);
@Override
public BooleanFormula isNegative(FloatingPointFormula pNumber) {
return wrapBool(isNegative(extractInfo(pNumber)));
}
protected abstract TFormulaInfo isNegative(TFormulaInfo pParam);
@Override
public FloatingPointFormula round(
FloatingPointFormula pFormula, FloatingPointRoundingMode pRoundingMode) {
return wrap(round(extractInfo(pFormula), pRoundingMode));
}
protected abstract TFormulaInfo round(
TFormulaInfo pFormula, FloatingPointRoundingMode pRoundingMode);
protected static String getBvRepresentation(BigInteger integer, int size) {
char[] values = new char[size];
for (int i = 0; i < size; i++) {
values[size - 1 - i] = integer.testBit(i) ? '1' : '0';
}
return String.copyValueOf(values);
}
}