pub struct Real(/* private fields */);Expand description
A CIM Float or Decimal value: the number, and the spelling it arrived in.
The number is the value; the spelling is how one document happened to write it. They
are kept apart for the same reason Mrid keeps a UUID apart from its spelling, and
the consequences are the same shape: two Reals that denote one number are equal
whatever they were written as, so a difference between two model states never reports
a change that is only a reformatting — while a re-export still reproduces the document
it read.
It matters because published models are full of forms no formatter would choose. The
CGMES 3.0 conformity corpus writes 2.62637E-05, 0e+000 and 250.000000; rendering
those as 0.0000262637, 0 and 250 re-exports a numerically identical model as a
textually different file, which is what a receiving system diffs. ENTSO-E’s RDF-Syntax
User Guide is explicit that engineering notation is chosen deliberately — from CIM18
active power travels as -90E6 rather than as -90000000 precisely to carry the
producer’s precision — so a number’s spelling is information, not noise.
A spelling is kept only when it is a conforming lexical form for the primitive it was
read as. The reader accepts 1,5 and 1.5D+3 from files that deviate
(Value::parse_primitive), and reproducing those would propagate a defect into
output this crate promises is valid; those are repaired to the canonical form, which is
the same stance the header takes on a malformed urn:uuid:.
Implementations§
Source§impl Real
impl Real
Sourcepub fn from_document(value: f64, text: &str, prim: Primitive) -> Real
pub fn from_document(value: f64, text: &str, prim: Primitive) -> Real
A number as a document wrote it.
The text is kept only when it differs from what this crate would write anyway and
is a conforming lexical form for prim — so a value that was already canonical
costs nothing, and a deviating one is repaired rather than echoed.
pub fn get(&self) -> f64
Sourcepub fn lexical(&self) -> Option<&str>
pub fn lexical(&self) -> Option<&str>
The spelling this value was read with, where it differs from the canonical form.
Sourcepub fn to_lexical_as(&self, prim: Primitive) -> String
pub fn to_lexical_as(&self, prim: Primitive) -> String
How to write it: the document’s spelling where there is one, else canonical.
Trait Implementations§
Source§impl PartialEq for Real
Equality is the number. The spelling is not part of the value, so 1.0 read from one
file equals 1 computed in memory — which is what keeps crate::diff from reporting
a change where a producer only changed its formatter.
impl PartialEq for Real
Equality is the number. The spelling is not part of the value, so 1.0 read from one
file equals 1 computed in memory — which is what keeps crate::diff from reporting
a change where a producer only changed its formatter.
It is f64 equality, so NaN equals nothing, itself included. CIM has no use for one
and no published model contains one, but a difference computed over a model that does
will report that value as changed on every run.