Skip to content

Regression: Unicode superscript no longer works #449

@pko-trackunit

Description

@pko-trackunit

Hi,

It seems that Unicode superscript is no longer treated as a power of 2, 3, etc.

import tech.units.indriya.format.SimpleUnitFormat;
import tech.units.indriya.unit.Units;
import javax.measure.MetricPrefix;

public class IndriyaSuperscriptBug {
    public static void main(String[] args) throws Exception {
        var fmt = SimpleUnitFormat.getInstance();

        // Caret notation works correctly
        var mm2_caret = fmt.parse("mm^2");
        var cm2_caret = fmt.parse("cm^2");
        System.out.println("100 mm^2 -> cm^2 = " + mm2_caret.getConverterToAny(cm2_caret).convert(100));

        // Unicode superscript is broken — prefix applied linearly instead of squared
        var mm2_super = fmt.parse("mm²");
        var cm2_super = fmt.parse("cm²");
        System.out.println("100 mm² -> cm² = " + mm2_super.getConverterToAny(cm2_super).convert(100));

        var mm2_correct = MetricPrefix.MILLI(Units.METRE).pow(2);
        System.out.println("parse(\"mm²\").equals(MILLI(m).pow(2)) = " + mm2_super.equals(mm2_correct));
    }
}

indriya 2.2.2 outputs:

100 mm^2 -> cm^2 = 1.0
100 mm² -> cm² = 1.0
parse("mm²").equals(MILLI(m).pow(2)) = true

indriya 2.2.3 outputs:

100 mm^2 -> cm^2 = 1.0
100 mm² -> cm² = 10.0
parse("mm²").equals(MILLI(m).pow(2)) = false

Is it expected? I checked the changelog, but didn't see anything obvious that could cause this. And I would hope a patch release would not have such breaking changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions