Sigh.
Here's what actually happens with float.to_int();
PHP:
if ( value.getType().equals( DataTypes.TYPE_STRING ) )
{
// Irrelevant, since we are passed a TYPE_FLOAT, not a TYPE_STRING
}
return new Value( value.intValue() );
and here's what actually happens with float.truncate();
PHP:
public static Value truncate( Interpreter interpreter, final Value arg )
{
return new Value( (long) arg.floatValue() );
}
So, the difference boils down to the difference between Value.intValue() and Value.floatValue() when value is a TYPE_FLOAT. Which is to say:
Code:
public long intValue()
{
if ( this.type.equals( DataTypes.TYPE_FLOAT ) )
{
return (long) Double.longBitsToDouble( this.contentLong );
}
return this.contentLong;
}
vs.
Code:
public double floatValue()
{
if ( !this.type.equals( DataTypes.TYPE_FLOAT ) )
{
return (double) this.contentLong;
}
return Double.longBitsToDouble( this.contentLong );
}
In either method, we do this:
- this.type.equals( DataTypes.TYPE_FLOAT )
- return Double.longBitsToDouble( this.contentLong )
One type.equals() comparison.
One call to Double.longBitsToDouble()
... which makes the final calculations, module type checks in this method vs. that method boil down to:
return new Value( (long) Double.longBitsToDouble( this.contentLong ) );
vs.
return new Value( (long) Double.longBitsToDouble( this.contentLong ) );
If you can see a difference there, you have better eyes than I do.
So, from this particular example you can see that, once interpreted, to_int has a much higher overhead than truncate,
Why "once interpreted"? When the interpreter executes the parse tree, it will call either to_int() or truncate(). The overhead to call either is a Java method call. Once inside one method or the other, the difference in overhead is this line in to_int():
Code:
if ( value.getType().equals( DataTypes.TYPE_STRING ) )
That is "much higher" overhead? Really?
JSR 223 came in with Java SE 6, whereas KoLmafia was originally written to be J2SE 1.4 compliant,
What the heck is JSR 223?
so holatuwol must've employed some other method to handle ASH commands and meet the JVM requirements.
1) holatuwol did not write ASH.
2) ASH is a Java package which has:
- a hand-written compiler which reads ASH programs and converts them into a parse tree
- an interpreter which executes the parse tree
3) I have no idea what it means to "meet the JVM requirements" other than "is a valid Java program"
I haven't read through the code on the interpreter and it's probably quite a kludge (due to poor support for dynamic languages in earlier versions of Java, not a shortcoming in holatuwol's abilities).
Sheesh. Now YOU are pissing me off.