Procházet zdrojové kódy

A few Number methods.

Herby Vojčík před 4 roky
rodič
revize
45b172b8c1
3 změnil soubory, kde provedl 123 přidání a 0 odebrání
  1. 9 0
      lang/API-CHANGES.txt
  2. 96 0
      lang/src/Kernel-Objects.js
  3. 18 0
      lang/src/Kernel-Objects.st

+ 9 - 0
lang/API-CHANGES.txt

@@ -1,3 +1,12 @@
+0.27.1:
+
++ Number >>
+  + isFinite
+  + isNaN
++ Number class >>
+  + negativeInfinity
+  + positiveInfinity
+
 0.27.0:
 
 + JSObjectProxy class >>

+ 96 - 0
lang/src/Kernel-Objects.js

@@ -3826,6 +3826,30 @@ return self;
 }; }),
 $globals.Number);
 
+$core.addMethod(
+$core.method({
+selector: "isFinite",
+protocol: "testing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "isFinite\x0a\x09\x22Answer whether the receiver is finite\x22\x0a\x09<inlineJS: 'return Number.isFinite(self)'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [["inlineJS:", ["return Number.isFinite(self)"]]],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return Number.isFinite(self);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isFinite",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Number);
+
 $core.addMethod(
 $core.method({
 selector: "isImmutable",
@@ -3844,6 +3868,30 @@ return true;
 }; }),
 $globals.Number);
 
+$core.addMethod(
+$core.method({
+selector: "isNaN",
+protocol: "testing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "isNaN\x0a\x09\x22Answer whether the receiver is IEEE-754 not-a-number\x22\x0a\x09<inlineJS: 'return Number.isNaN(self)'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [["inlineJS:", ["return Number.isNaN(self)"]]],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return Number.isNaN(self);
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"isNaN",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Number);
+
 $core.addMethod(
 $core.method({
 selector: "isNumber",
@@ -4824,6 +4872,30 @@ return self;
 }; }),
 $globals.Number.a$cls);
 
+$core.addMethod(
+$core.method({
+selector: "negativeInfinity",
+protocol: "instance creation",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "negativeInfinity\x0a\x09<inlineJS: 'return Number.NEGATIVE_INFINITY'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [["inlineJS:", ["return Number.NEGATIVE_INFINITY"]]],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return Number.NEGATIVE_INFINITY;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"negativeInfinity",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Number.a$cls);
+
 $core.addMethod(
 $core.method({
 selector: "pi",
@@ -4848,6 +4920,30 @@ return self;
 }; }),
 $globals.Number.a$cls);
 
+$core.addMethod(
+$core.method({
+selector: "positiveInfinity",
+protocol: "instance creation",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "positiveInfinity\x0a\x09<inlineJS: 'return Number.POSITIVE_INFINITY'>",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [["inlineJS:", ["return Number.POSITIVE_INFINITY"]]],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return Number.POSITIVE_INFINITY;
+return self;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"positiveInfinity",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Number.a$cls);
+
 $core.addMethod(
 $core.method({
 selector: "radiansPerDegree",

+ 18 - 0
lang/src/Kernel-Objects.st

@@ -1048,10 +1048,20 @@ even
 	^ 0 = (self \\ 2)
 !
 
+isFinite
+	"Answer whether the receiver is finite"
+	<inlineJS: 'return Number.isFinite(self)'>
+!
+
 isImmutable
 	^ true
 !
 
+isNaN
+	"Answer whether the receiver is IEEE-754 not-a-number"
+	<inlineJS: 'return Number.isNaN(self)'>
+!
+
 isNumber
 	^ true
 !
@@ -1092,10 +1102,18 @@ e
 	<inlineJS: 'return Math.E;'>
 !
 
+negativeInfinity
+	<inlineJS: 'return Number.NEGATIVE_INFINITY'>
+!
+
 pi
 	<inlineJS: 'return Math.PI'>
 !
 
+positiveInfinity
+	<inlineJS: 'return Number.POSITIVE_INFINITY'>
+!
+
 radiansPerDegree
 	^ (self pi) / 180
 ! !