Skip to content
Topaz6.0 · Before release
Download

Search documentation

Specification 6.0 · Not released · Tested product 5.21.3

Use arrow keys to choose a result. Press Enter to open.

Type an API name, diagnostic number, rule, or project topic.

    Library · std.typeset

    Length.toScaledPoints for In

    Converts a physical length to its integer scaled-point representation.

    toScaledPoints() -> int
    Receiver
    Length<In>
    Minimum arity
    0
    Maximum arity
    0

    Declaration and parameters

    Link

    Availability

    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

    Receiver

    Length<In>

    Parameter constraints

    Physical Length values with the Pt, Mm, Cm, or In marker provide toScaledPoints returning int. One point is 65,536 scaled points. The result is the exact stored signed 64-bit count.

    The scaledPoints member is absent from every Length type. Calling that removed member is rejected with TPZ5006. Length<Em> has no toScaledPoints member and must resolve to a physical length first.

    fromScaledPoints accepts every int from -9223372036854775808 through 9223372036854775807 inclusive. It returns Length<Pt> with that exact scaled-point count. Zero and negative inputs are valid. Construction performs no rounding and has no value-dependent failure.

    fromMilliPoints interprets its int argument as thousandths of a point. Its scaled-point result is roundEven of the exact rational input times 8192 divided by 125.

    fromMilliPoints accepts -140737488355328000 through 140737488355327999 inclusive. An input outside that range stops with runtime diagnostic TPZ4004. It does not return Result, wrap, saturate, or clamp.

    Length<Pt>.toMilliPoints returns roundEven of the exact stored count times 125 divided by 8192. Every representable point length has a representable int result.

    roundEven selects the nearest integer and chooses the even integer at an exact tie. Positive and negative ties follow the same rule. Range checking applies to the final rounded value. Intermediate arithmetic must preserve the exact rational value.

    A count of 4096 scaled points converts to 62 millipoints. A count of 12288 converts to 188. Their negatives convert to -62 and -188. One millipoint constructs 66 scaled points and negative one constructs -66.

    Millipoint conversion can lose scaled-point precision. A conversion to millipoints and back need not recover the original length. The maximum point length converts to 140737488355328000 millipoints, which exceeds the fromMilliPoints input range.

    The constructors require int arguments. A float or Length argument is rejected with TPZ5001. Physical conversions and scalar arithmetic do not provide an implicit integer constructor.

    A constructor evaluates its argument once before checking the result range. A receiver conversion evaluates its receiver once. These operations perform no I/O or mutation and read no font or paragraph state.

    A fromMilliPoints overflow is reported at the public constructor call. Earlier argument effects remain visible and later expressions do not execute.

    Result

    The declared result type is int.

    Effects

    Failures

    Result and effects

    Link

    Return the exact signed scaled-point count. Every stored physical value is valid and one point contains 65,536 scaled points. The conversion performs no rounding and has no value-dependent failure.

    Why

    Link

    Integer conversions use the same to prefix as unit conversions and collection conversions. Scaled points and millipoints remain distinct because they represent different units and rounding boundaries.

    Related entries

    Link

    std.typeset

    Convert physical lengths with toScaledPoints

    Link
    Ruletopaz.stdlib.contract.to-scaled-points.rule

    Convert physical lengths with toScaledPoints

    Physical Length values with the Pt, Mm, Cm, or In marker provide toScaledPoints returning int. One point is 65,536 scaled points. The result is the exact stored signed 64-bit count.

    The scaledPoints member is absent from every Length type. Calling that removed member is rejected with TPZ5006. Length<Em> has no toScaledPoints member and must resolve to a physical length first.

    fromScaledPoints accepts every int from -9223372036854775808 through 9223372036854775807 inclusive. It returns Length<Pt> with that exact scaled-point count. Zero and negative inputs are valid. Construction performs no rounding and has no value-dependent failure.

    fromMilliPoints interprets its int argument as thousandths of a point. Its scaled-point result is roundEven of the exact rational input times 8192 divided by 125.

    fromMilliPoints accepts -140737488355328000 through 140737488355327999 inclusive. An input outside that range stops with runtime diagnostic TPZ4004. It does not return Result, wrap, saturate, or clamp.

    Length<Pt>.toMilliPoints returns roundEven of the exact stored count times 125 divided by 8192. Every representable point length has a representable int result.

    roundEven selects the nearest integer and chooses the even integer at an exact tie. Positive and negative ties follow the same rule. Range checking applies to the final rounded value. Intermediate arithmetic must preserve the exact rational value.

    A count of 4096 scaled points converts to 62 millipoints. A count of 12288 converts to 188. Their negatives convert to -62 and -188. One millipoint constructs 66 scaled points and negative one constructs -66.

    Millipoint conversion can lose scaled-point precision. A conversion to millipoints and back need not recover the original length. The maximum point length converts to 140737488355328000 millipoints, which exceeds the fromMilliPoints input range.

    The constructors require int arguments. A float or Length argument is rejected with TPZ5001. Physical conversions and scalar arithmetic do not provide an implicit integer constructor.

    A constructor evaluates its argument once before checking the result range. A receiver conversion evaluates its receiver once. These operations perform no I/O or mutation and read no font or paragraph state.

    A fromMilliPoints overflow is reported at the public constructor call. Earlier argument effects remain visible and later expressions do not execute.

    Why

    Integer conversions use the same to prefix as unit conversions and collection conversions. Scaled points and millipoints remain distinct because they represent different units and rounding boundaries.

    Source evidence

    Convert every physical length unit to scaled points

    Link
    main.tpzConvert every physical length unit to scaled pointsOpen in Playground
    1. import std.io
    2. import std.typeset as ts
    3. let pt = (1pt).toScaledPoints()
    4. let mm = (25.4mm).toScaledPoints()
    5. let cm = (2.54cm).toScaledPoints()
    6. let inch = (1in).toScaledPoints()
    7. io.writeLine("{pt}|{mm}|{cm}|{inch}|{ts.fromScaledPoints(pt) == 1pt}")
    Expected outputexit 0
    65536|4718592|4718592|4718592|true
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 65536|4718592|4718592|4718592|true
    Source evidence

    Keep the millipoint conversion boundary

    Link
    main.tpzKeep the millipoint conversion boundaryOpen in Playground
    1. import std.io
    2. import std.typeset as ts
    3. let tie = ts.fromScaledPoints(4096).toMilliPoints()
    4. let rounded = ts.fromMilliPoints(1) == ts.fromScaledPoints(66)
    5. io.writeLine("{tie}|{rounded}")
    Expected outputexit 0
    62|true
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 62|true
    Source evidence

    Reject scaledPoints on `Length<Pt>`

    Link
    main.tpzReject scaledPoints on `Length<Pt>`Open in Playground
    1. let distance = 1pt
    2. distance.scaledPoints()
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5006 stdlib-removed-scaled-points at main.tpz:2:10
    Source evidence

    Reject scaledPoints on `Length<Mm>`

    Link
    main.tpzReject scaledPoints on `Length<Mm>`Open in Playground
    1. let distance = 1mm
    2. distance.scaledPoints()
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5006 stdlib-removed-scaled-points at main.tpz:2:10
    Source evidence

    Reject scaledPoints on `Length<Cm>`

    Link
    main.tpzReject scaledPoints on `Length<Cm>`Open in Playground
    1. let distance = 1cm
    2. distance.scaledPoints()
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5006 stdlib-removed-scaled-points at main.tpz:2:10
    Source evidence

    Reject scaledPoints on `Length<In>`

    Link
    main.tpzReject scaledPoints on `Length<In>`Open in Playground
    1. let distance = 1in
    2. distance.scaledPoints()
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5006 stdlib-removed-scaled-points at main.tpz:2:10
    Source evidence

    Resolve font-relative lengths before integer conversion

    Link
    main.tpzResolve font-relative lengths before integer conversionOpen in Playground
    1. let distance = 1em
    2. distance.toScaledPoints()
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5006 stdlib-unresolved-em-scaled-points at main.tpz:2:10
    Source evidence

    Read both endpoints of the exact integer representation

    Link
    main.tpzRead both endpoints of the exact integer representationOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let low = ts.fromScaledPoints(-9223372036854775808).toScaledPoints()
    4. let high = ts.fromScaledPoints(9223372036854775807).toScaledPoints()
    5. io.writeLine("{low}|{high}")
    Expected outputexit 0
    -9223372036854775808|9223372036854775807
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. -9223372036854775808|9223372036854775807
    Source evidence

    Construct the millipoint endpoints and keep signed rounding

    Link
    main.tpzConstruct the millipoint endpoints and keep signed roundingOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let low = ts.fromMilliPoints(-140737488355328000)
    4. let high = ts.fromMilliPoints(140737488355327999)
    5. let negative = ts.fromMilliPoints(-1)
    6. let lowGrid = ts.fromScaledPoints(-9223372036854775808).toMilliPoints()
    7. let highGrid = ts.fromScaledPoints(9223372036854775807).toMilliPoints()
    8. io.writeLine("{low == -140737488355328pt}|{high == ts.fromScaledPoints(9223372036854775742)}|{negative == ts.fromScaledPoints(-66)}")
    9. io.writeLine("{lowGrid}|{highGrid}")
    Expected outputexit 0
    true|true|true
    -140737488355328000|140737488355328000
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. true|true|true
    2. -140737488355328000|140737488355328000
    Source evidence

    Round both signs and both sides of a millipoint tie

    Link
    main.tpzRound both signs and both sides of a millipoint tieOpen in Playground
    1. import std.typeset as ts
    2. import std.io
    3. let below = ts.fromScaledPoints(4095).toMilliPoints()
    4. let tie = ts.fromScaledPoints(4096).toMilliPoints()
    5. let above = ts.fromScaledPoints(4097).toMilliPoints()
    6. let negativeBelow = ts.fromScaledPoints(-4095).toMilliPoints()
    7. let negativeTie = ts.fromScaledPoints(-4096).toMilliPoints()
    8. let negativeAbove = ts.fromScaledPoints(-4097).toMilliPoints()
    9. let upperTie = ts.fromScaledPoints(12288).toMilliPoints()
    10. let negativeUpperTie = ts.fromScaledPoints(-12288).toMilliPoints()
    11. io.writeLine("{below}|{tie}|{above}|{negativeBelow}|{negativeTie}|{negativeAbove}|{upperTie}|{negativeUpperTie}")
    Expected outputexit 0
    62|62|63|-62|-62|-63|188|-188
    
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Execution completes. Exit code 0.

    Expected stdout
    1. 62|62|63|-62|-62|-63|188|-188
    Source evidence

    Reject a millipoint input above the representable range

    Link
    main.tpzReject a millipoint input above the representable rangeOpen in Playground
    1. import std.typeset as ts
    2. ts.fromMilliPoints(140737488355328000)
    Expected outputNonzero exit
    No stdout.
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • TPZ4004 stdlib-length-unrepresentable at main.tpz:2:1
    Source evidence

    Reject a millipoint input below the representable range

    Link
    main.tpzReject a millipoint input below the representable rangeOpen in Playground
    1. import std.typeset as ts
    2. ts.fromMilliPoints(-140737488355328001)
    Expected outputNonzero exit
    No stdout.
    $ topaz run main.tpz · target product 5.21.3
    Expected result

    Expected result

    Rejection during run. Nonzero exit.

    • TPZ4004 stdlib-length-unrepresentable at main.tpz:2:1
    Source evidence

    Require an int for fromScaledPoints

    Link
    main.tpzRequire an int for fromScaledPointsOpen in Playground
    1. import std.typeset as ts
    2. ts.fromScaledPoints(1.0)
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-length-int-required at main.tpz:2:21
    Source evidence

    Require an int for fromMilliPoints

    Link
    main.tpzRequire an int for fromMilliPointsOpen in Playground
    1. import std.typeset as ts
    2. ts.fromMilliPoints(1.0)
    Expected outputNonzero exit
    No stdout.
    $ topaz check main.tpz --format json · target product 5.21.3
    Expected result

    Expected result

    Rejection during check. Nonzero exit.

    • TPZ5001 stdlib-length-int-required at main.tpz:2:20
    Source evidence

    Diagnostics

    Link

    Unknown member or field

    Integer overflow

    TPZ5001

    Menu

    Download