Skip to content

Instantly share code, notes, and snippets.

@colomon
Created January 15, 2012 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colomon/1614246 to your computer and use it in GitHub Desktop.
Save colomon/1614246 to your computer and use it in GitHub Desktop.
public static P6any GetNumber(Variable v, P6any o, out int rank) {
if (o.mo.num_rank >= 0) {
rank = o.mo.num_rank;
} else {
if (o.Does(Kernel.RealMO)) { # new code starts here
rank = NR_FLOAT;
return MakeFloat(o.InvokeMethod(Kernel.GetInferiorRoot(), "Bridge", null, null));
} else { # and ends here
o = o.mo.mro_Numeric.Get(v).Fetch();
rank = o.mo.num_rank;
if (rank < 0)
throw new NieczaException("Not a valid primitive number " +
o.mo.name);
}
}
if (rank == NR_FIXINT && o is BoxObject<BigInteger>)
rank = NR_BIGINT;
return o;
}
<new Real type>.abs gets me
Unhandled exception: System.InvalidCastException: Cannot cast from source type to destination type.
at Builtins.PromoteToFloat (Int32 rank, Niecza.P6any vret) [0x00000] in <filename unknown>:0
at Builtins.abs (Niecza.Variable a1) [0x00000] in <filename unknown>:0
at Run.CORE.C967prefix:<abs> (Niecza.Frame ) [0x00000] in <filename unknown>:0
at Niecza.Kernel.RunCore (Niecza.Frame& cur) [0x00000] in <filename unknown>:0
at /Users/colomon/tools/niecza/lib/CORE.setting line 0 (prefix:<abs> @ 1)
at /Users/colomon/tools/niecza/lib/CORE.setting line 364 (Cool.abs @ 3)
at /Users/colomon/tools/niecza/t/spec/S32-num/real-bridge.t line 44 (mainline @ 23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment