[#mp_units-truncated_t]
= xref:mp_units.adoc[mp&lowbar;units]::truncated&lowbar;t
:relfileprefix: ../
:mrdocs:

Tag type for the `truncated` rounding policy

== Synopsis

Declared in `&lt;mp&hyphen;units&sol;framework&sol;rounding&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
struct truncated&lowbar;t;
----

== Description

A conversion without a policy (e&period;g&period; `q&period;in(u)`) is only available when the framework considers it value&hyphen;preserving (following the `std&colon;&colon;chrono` convention, a floating&hyphen;point destination is always considered such)&period; For the conversions considered truncating (e&period;g&period; an integral representation scaled by a non&hyphen;integral factor, or a narrowing of the representation type), the user has to explicitly state what should happen to the information that does not fit by passing a rounding policy as the last function argument&colon;

[,cpp]
----
quantity q1 = (1234 * m).in(km, truncated);          // 1 km
quantity q2 = (1567 * m).in(km, rounded);            // 2 km
quantity q3 = (-1500 * m).in(km, rounded_down);      // -2 km
quantity q4 = (1.23 * s).in<int>(ms, rounded_up);    // 1231 ms
----
The policy specifies how to round the exact conversion result to a value representable in the destination type&colon;

* `truncated` &hyphen; the semantics of `static&lowbar;cast` and `std&colon;&colon;chrono&colon;&colon;duration&lowbar;cast`&colon; rounds towards zero for an integral destination&semi; a floating&hyphen;point destination converts to the nearest representable value,
* `rounded` &hyphen; rounds to the nearest representable value, to even in halfway cases (the semantics of `std&colon;&colon;chrono&colon;&colon;round`),
* `rounded&lowbar;down` &hyphen; rounds towards negative infinity (the semantics of `std&colon;&colon;chrono&colon;&colon;floor`),
* `rounded&lowbar;up` &hyphen; rounds towards positive infinity (the semantics of `std&colon;&colon;chrono&colon;&colon;ceil`)&period;

A floating&hyphen;point destination represents every conversion result with a rounding error of at most half ULP (`rounded` semantics), and the directed modes cannot be delivered for it, which is why it accepts only the `truncated` and `rounded` policies&period;

Note that `mp&lowbar;units&colon;&colon;floor&sol;ceil&sol;round&lt;U&gt;(q)` perform a different operation&colon; they round to an integral multiple of the target unit even when the representation could store the exact result (e&period;g&period; for a floating&hyphen;point representation)&period; The policies never adjust a value that the destination represents exactly&period; Both coincide for integral representations&period;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:mp_units/truncated_t/2constructor.adoc[`truncated&lowbar;t`]         [.small]#[constructor]#
| Default constructor
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
