Skip to content

Instantly share code, notes, and snippets.

@colomon
Created July 11, 2013 10:22
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/5974310 to your computer and use it in GitHub Desktop.
Save colomon/5974310 to your computer and use it in GitHub Desktop.
So, I figured out how to make bigints work for nqp sprintf:
my $knowhow := nqp::knowhow().new_type(:repr("P6bigint"));
if nqp::eqaddr($number_representation.WHAT, 1.WHAT) {
nqp::box_i($number_representation, $knowhow);
} else {
if nqp::eqaddr($number_representation.WHAT, 1.01.WHAT)
|| nqp::eqaddr($number_representation.WHAT, "1.01".WHAT) {
if $number_representation > 0 {
nqp::fromnum_I(nqp::floor_n($number_representation), $knowhow);
}
else {
nqp::fromnum_I(nqp::ceil_n($number_representation), $knowhow);
}
} else {
$number_representation;
}
}
(This clearly isn't complete, it assumes you're passed either an int, a num, a str, or a bigint.)
This *works* in the NQP test file. Unfortunately, it also completely breaks Jakudo's sprintf; the very first time S32-str/sprintf.t tries to print out a simple Int, it dies with
===SORRY!===
java.lang.RuntimeException: Cannot access a reference attribute as a native attribute
Help?
Ideally, of course, when used in Jakudo this code should call .Int to intify arguments which are supposed to be Ints...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment