Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Issue #5637: Add attribute Integer.nearestFloat.
Browse files Browse the repository at this point in the history
The Java implementation is a simple cast, the JavaScript implementation does the same as `Number.float` (i.e. calls `Float(this.valueOf())`.
  • Loading branch information
ePaul committed Sep 20, 2015
1 parent d547f56 commit cb3567a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions language/runtime-js/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ atr$(JSNum$proto, 'character', function(){
}
return Character(this.valueOf());
},undefined,function(){return{an:function(){return[shared(),actual()]},mod:$CCMM$,$cont:Integer,d:['$','Integer','$at','character']};});
atr$(JSNum$proto, 'nearestFloat', function(){ return Float(this.valueOf()); },
undefined,function(){return{an:function(){return[shared(),actual()]},mod:$CCMM$,$cont:Integer,d:['$','Integer','$at','nearestFloat']};});
atr$(JSNum$proto, 'successor', function(){ return this+1; },
undefined,function(){return{an:function(){return[shared(),actual()]},mod:$CCMM$,$cont:Ordinal,d:['$','Ordinal','$at','successor']};});
atr$(JSNum$proto, 'predecessor', function(){ return this-1; },
Expand Down
9 changes: 9 additions & 0 deletions language/runtime/ceylon/language/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ public static double getFloat(long value) {
}
}

public double getNearestFloat() {
return (double) value;
}

@Ignore
public static double getNearestFloat(long value) {
return (double) value;
}

public byte getByte() {
return getByte(value);
}
Expand Down
12 changes: 11 additions & 1 deletion language/src/ceylon/language/Integer.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,17 @@ shared native final class Integer(Integer integer)
"if the number cannot be represented as a `Float`
without loss of precision")
shared native Float float;


"The nearest [[Float]] to this number. For
Integers in magnitude less than 2^53, this is always
a Float with the exact same mathematical value (and the
same value as [[float]]), for larger ones on the JVM the
Floats are less dense than the Integers so there can be some
loss of precision.
This method never throws an OverflowException."
shared native Float nearestFloat;

shared actual native Integer predecessor;
shared actual native Integer successor;
shared actual native Integer neighbour(Integer offset);
Expand Down

0 comments on commit cb3567a

Please sign in to comment.