aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/logic/src/main/java/tools/refinery/logic/term/int_/RealToIntTerm.java
blob: 7611af903a1fd5d8ad82f43c53034eba1a6ab067 (plain) (blame)
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
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.logic.term.int_;

import tools.refinery.logic.term.Term;
import tools.refinery.logic.term.UnaryTerm;
import tools.refinery.logic.substitution.Substitution;

public class RealToIntTerm extends UnaryTerm<Integer, Double> {
	protected RealToIntTerm(Term<Double> body) {
		super(Integer.class, Double.class, body);
	}

	@Override
	protected Integer doEvaluate(Double bodyValue) {
		return bodyValue.isNaN() ? null : bodyValue.intValue();
	}

	@Override
	protected Term<Integer> doSubstitute(Substitution substitution, Term<Double> substitutedBody) {
		return new RealToIntTerm(substitutedBody);
	}

	@Override
	public String toString() {
		return "(%s as int)".formatted(getBody());
	}
}