| Online Eiffel Documentation

EiffelStudio

# More precision

TIME and TIME_DURATION are designed to deal with high precision in time. The only limit is the one from number representation.

The classes TIME and TIME_DURATION have an attribute fine_second (inherited from TIME_VALUE) which allows high precision. This attribute represents the number of seconds with fractions (it is an instance of DOUBLE). From this attribute are calculated second and fractional_second (which are functions): second is the truncated-to-integer part and fractional_second is the difference between the two previous one, so that the sum of second and fractional_second is always equal to fine_second (see invariant in TIME_VALUE).

As a result of this, when fine_second is positive (3.55 for example), second and fractional_second are also positive (3 and 0.55). When fine_second is negative (- 3.55 for example), second and fractional_second are also negative (- 3 and - 0.55).

Manipulation on second and fractional_second are in fact always made through fine_second. Users who do not want to deal with precision do not need to care about this.

Features dealing with fine_second and fractional_second are described here.

#### Creation (common to TIME, TIME_DURATION )

- make_fine looks like make but it takes a DOUBLE for its third argument (instead of an INTEGER). fine_second is then set to this value.
- make_by_fine_seconds looks like make_by_seconds but it takes a DOUBLE for argument (instead of an INTEGER). Comparison (common) There are no new features. The same ones are available since they are written to deal with precision. It is possible to compare two instances, one with precision and the other one without.

#### Measurement and access

In TIME:

- fine_seconds looks like seconds but it contains fractions.

In TIME_DURATION:

- fine_seconds_count looks like seconds_count but it contains fractions.

#### Element change

- set_fine_second allows to set directly fine_second to a DOUBLE. In TIME, a precondition requires that the argument stands in the allowed range.
- set_fractionals allows to set directly fractional_second to a DOUBLE. In TIME a precondition requires that the argument is positive and smaller than one. In TIME_DURATION the precondition is particular: it is not allowed to have an argument with a different sign than second. Otherwise, as long as fractional_second and second are linked to fine_second, such a setting would mean that second is also changed and fractional_second set to a different value. For example if fine_second = 4.5 (then second = 4 and fractional_second = 0.5) and - 0.8 is the argument of set_fractionals.

The result of that would be fine_second = 3.2 (then second = 3 and fractional_second = 0.2). It is better to prohibit that.

Comment: feature set_second (from both TIME and TIME_DURATION) will cut down fractional_second to zero.

#### Operations

- fine_second_add looks like second_add but takes a DOUBLE for argument.

In TIME_DURATION:

- canonical and to_canonical deals already with precision. There is nothing different.