to Mm() - > Length<Mm>- Module
- std.
typeset - Receiver
- Length<Cm>
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.typeset in language mode 5.21.
The current compiler selects std/typeset.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1307 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 40 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1307 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 522 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_self_frontend/topaz/checker/model.tpz at
b48527d0a174· 694 - compiler/crates/topaz_self_frontend/topaz/checker/model.tpz at
b48527d0a174· 697
Receiver
Length<Cm>
Parameter constraints
Every physical Length stores a signed 64-bit scaled-point count and a unit marker. The inclusive count range is -9223372036854775808 through 9223372036854775807. Zero and negative lengths are valid.
One point is 65,536 scaled points. One inch is 72 points and exactly 25.4 millimetres. One centimetre is 10 millimetres.
A physical literal converts its exact decimal value to scaled points and rounds once to the nearest integer. An exact tie selects the even integer. The same rule applies to either sign.
The methods toPt, toMm, toCm, and toIn accept no arguments on Length<Pt>, Length<Mm>, Length<Cm>, and Length<In>. They return the named physical unit with the original scaled-point count.
A unit conversion performs no further rounding and cannot overflow. Converting to the existing unit returns the same typed value. Every conversion sequence preserves the physical distance and stored count.
The unit marker remains part of the static type. Assignment and function arguments do not convert units implicitly. A required Length<Pt> rejects another unit with TPZ5001. Convert explicitly before the call or assignment.
Length<Em> has no physical conversion member. Resolve it with an explicit positive point font size before converting units.
Each method evaluates its receiver once before producing the result. Conversion performs no I/O or mutation and reads no font or paragraph state.
Use toScaledPoints on any physical unit for the exact stored integer. Convert to Length<Pt> before calling toMilliPoints. The integer conversion contract defines its separate rounding boundary.
Result
The declared result type is Length<Mm>.
Effects
Failures
Result and effects
LinkReturn Length<Mm> with the exact stored scaled-point count. This accepts the full signed Length range, including zero and negative values. The conversion does not round, overflow, or consult a font.
Why
LinkA physical unit belongs to the length type. Explicit conversion changes the unit marker while preserving the physical distance and its scaled-point grid value.
Resolved contracts
LinkRelated entries
LinkConvert physical units without rounding again
LinkConvert physical units without rounding again
Every physical Length stores a signed 64-bit scaled-point count and a unit marker. The inclusive count range is -9223372036854775808 through 9223372036854775807. Zero and negative lengths are valid.
One point is 65,536 scaled points. One inch is 72 points and exactly 25.4 millimetres. One centimetre is 10 millimetres.
A physical literal converts its exact decimal value to scaled points and rounds once to the nearest integer. An exact tie selects the even integer. The same rule applies to either sign.
The methods toPt, toMm, toCm, and toIn accept no arguments on Length<Pt>, Length<Mm>, Length<Cm>, and Length<In>. They return the named physical unit with the original scaled-point count.
A unit conversion performs no further rounding and cannot overflow. Converting to the existing unit returns the same typed value. Every conversion sequence preserves the physical distance and stored count.
The unit marker remains part of the static type. Assignment and function arguments do not convert units implicitly. A required Length<Pt> rejects another unit with TPZ5001. Convert explicitly before the call or assignment.
Length<Em> has no physical conversion member. Resolve it with an explicit positive point font size before converting units.
Each method evaluates its receiver once before producing the result. Conversion performs no I/O or mutation and reads no font or paragraph state.
Use toScaledPoints on any physical unit for the exact stored integer. Convert to Length<Pt> before calling toMilliPoints. The integer conversion contract defines its separate rounding boundary.
Why
A unit marker states how a length may be used while one physical grid preserves its distance. Conversion changes the marker without accumulating rounding error. One conversion name per target unit works for every physical source unit.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1303-1313 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 19-29 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 39-58 - compiler/crates/topaz_syntax/src/length.rs at
b48527d0a174· 290-292 - compiler/crates/topaz_value/src/value/length.rs at
b48527d0a174· 119-137 -
topaz.stdlib.contract.physical-length-conversionatworking-tree
Convert each physical unit to every physical target
Linkimport std.iolet pt = 72ptlet mm = 25.4mmlet cm = 2.54cmlet inch = 1inio.writeLine("{pt.toPt() == 72pt}|{pt.toMm() == 25.4mm}|{pt.toCm() == 2.54cm}|{pt.toIn() == 1in}")io.writeLine("{mm.toPt() == 72pt}|{mm.toMm() == 25.4mm}|{mm.toCm() == 2.54cm}|{mm.toIn() == 1in}")io.writeLine("{cm.toPt() == 72pt}|{cm.toMm() == 25.4mm}|{cm.toCm() == 2.54cm}|{cm.toIn() == 1in}")io.writeLine("{inch.toPt() == 72pt}|{inch.toMm() == 25.4mm}|{inch.toCm() == 2.54cm}|{inch.toIn() == 1in}")
true|true|true|true true|true|true|true true|true|true|true true|true|true|true
Expected result
Expected result
Execution completes. Exit code 0.
true|true|true|truetrue|true|true|truetrue|true|true|truetrue|true|true|true
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1303-1313 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 19-29 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 39-58 - compiler/crates/topaz_syntax/src/length.rs at
b48527d0a174· 290-292 - compiler/crates/topaz_value/src/value/length.rs at
b48527d0a174· 119-137 -
topaz.stdlib.contract.physical-length-conversionatworking-tree
Preserve signed and quantized values through conversion chains
Linkimport std.typeset as tsimport std.iolet negative = (-1pt).toMm().toCm().toIn().toPt()let zero = (0mm).toIn().toPt()let metric = (0.1mm).toPt()let unchanged = metric.toCm().toMm().toIn().toPt()io.writeLine("{negative == -1pt}|{zero == 0pt}|{metric == ts.fromScaledPoints(18577)}|{unchanged == ts.fromScaledPoints(18577)}")
true|true|true|true
Expected result
Expected result
Execution completes. Exit code 0.
true|true|true|true
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1303-1313 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 19-29 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 39-58 - compiler/crates/topaz_syntax/src/length.rs at
b48527d0a174· 290-292 - compiler/crates/topaz_value/src/value/length.rs at
b48527d0a174· 119-137 -
topaz.stdlib.contract.physical-length-conversionatworking-tree
Keep the full range when changing units
Linkimport std.typeset as tsimport std.iolet low = ts.fromScaledPoints(-9223372036854775808).toMm().toCm().toIn().toPt()let high = ts.fromScaledPoints(9223372036854775807).toIn().toCm().toMm().toPt()io.writeLine("{low == -140737488355328pt}|{high == 140737488355327.9999847412109375pt}")
true|true
Expected result
Expected result
Execution completes. Exit code 0.
true|true
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1303-1313 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 19-29 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 39-58 - compiler/crates/topaz_syntax/src/length.rs at
b48527d0a174· 290-292 - compiler/crates/topaz_value/src/value/length.rs at
b48527d0a174· 119-137 -
topaz.stdlib.contract.physical-length-conversionatworking-tree
Require the declared physical unit after conversion
Linklet distance: Length<Pt> = (1pt).toMm()
No stdout.
Expected result
Expected result
Rejection during check. Nonzero exit.
TPZ5001stdlib-physical-distance-requires-points atmain.tpz:1:28
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1303-1313 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 19-29 - compiler/crates/topaz_self_frontend/topaz/length.tpz at
b48527d0a174· 39-58 - compiler/crates/topaz_syntax/src/length.rs at
b48527d0a174· 290-292 - compiler/crates/topaz_value/src/value/length.rs at
b48527d0a174· 119-137 -
topaz.stdlib.contract.physical-length-conversionatworking-tree