NOTE: This type is introduced in CPN Tools 3.5.5.
Real numbers are distinguished from integers by the decimal point. The period separates the integer part from the fractional part. One or more digits must follow after the decimal point. The real color set is large.
IMPORTANT: Reals are NOT equality types in Standard ML. In the CPN ML variant used in CPN Tools this has been modified, meaning you should be able to use reals as any other type, but beware that equality is still dodgy because of rounding errors. We recommend against relying on exact comparisons, and instead use only inequalities using reals (expressions like x < 1.1
). While reals work with the state space tool, we recommend against using reals with state space analysis.
For now, reals are considered experimental due to the very fundamental changes needed to make them work; we welcome any error reports regarding reals, but do not otherwise provide any support for this type before the release of 4.0.
Declaration Syntax
colset name = real [with real-exp1..real-exp2];
Order
usual ordering of numbers
Optional with Clause
Restricts the real color set to an interval determined by the two expressions real-exp1
and real-exp2
. It must be the case that real-exp1
<=real-exp2
.
Declaration Examples
color R = real;
color SomeReal = real with 1.0..3.5;
var someReal : SomeReal;
The CPN variable someReal
may have a range of real values from 1.0 to 3.5. For example, 1.0 and 3.234 are legal values, but 1 and 4.2 are not.
Operations
~r
: negation of the integer valuer
r1 + r2
: additionr1 - ri2
: subtractionr1 * ri2
: multiplicationr1 / r2
: divisionReal.==(r1,r2)
: returns true if and only if neitherr1
norr2
is NaN, andr1
andr2
are equalabs r
: absolute value ofr
floor r
: return largest integer not larger thanr
ceil r
: return smallest integer not less thanr
trunc r
: roundr
towards zeroround r
: return integer nearest tor
real i
: convert integeri
to real valueReal.min(r1,r2)
: minimum ofr1
andr2
Real.max(r1,r2)
: maximum ofr1
andr2
Math.sqrt
r: square root ofr
Math.ln
r: natural logarithmMath.exp
r: exponentialMath.sin
r: sineMath.cos
r: cosineMath.tan
r: tangentMath.arctan r
: arc tangent
The trigonometric functions all work in units of radians.
For additional details and functions see the REAL signature and the MATH signature in the SML Basis Library.
See also color set functions.
You must be logged in to post a comment.