Skip to content

dynamic interfaces & numbers #575

@jvasileff

Description

@jvasileff

I'm not sure how JS numbers are really supposed to work, but currently dynamic blocks do what I want, and dynamic interfaces do not:

dynamic JSMath {
    shared formal Float sin(Float x);
}

JSMath jsMath {
    dynamic { return \iMath; }
}

shared void run() {
    print(jsMath.sin(3.14159/2.0));   // 0.9999999999991198 (good)
    print((jsMath.sin(3.14159/2.0) of Anything) is Float); // true (good)
    print((jsMath.sin(3.14159/2.0) of Anything) is Integer); // false (good)

    print(jsMath.sin(0.0)); // 0 (Not 0.0)
    print((jsMath.sin(0.0) of Anything) is Float); // false
    print((jsMath.sin(0.0) of Anything) is Integer); // true

    Float result;
    dynamic {
        result = \iMath.sin(0.0);
    }
    print(result); // 0.0 (good)
    print((result of Anything) is Float); // true (good)
    print((result of Anything) is Integer); // false (good)
}

As you can see, sometimes I wind up with a Ceylon Float, and sometimes an Integer. This also affects results like -0.0 vs. +0.0, and perhaps infinity and undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions