@@ -27,6 +27,11 @@ var p5 = require('../core/main');
2727 * var diameter = float(str);
2828 * ellipse(width / 2, height / 2, diameter, diameter);
2929 * </code></div>
30+ * <div class='norender'><code>
31+ * print(float('10.31')); // 10.31
32+ * print(float('Infinity')); // Infinity
33+ * print(float('-Infinity')); // -Infinity
34+ * </code></div>
3035 *
3136 * @alt
3237 * 20 by 20 white ellipse in the center of the canvas
@@ -57,6 +62,8 @@ p5.prototype.float = function(str) {
5762 * print(int(true)); // 1
5863 * print(int(false)); // 0
5964 * print(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9]
65+ * print(int(Infinity)); // Infinity
66+ * print(int('-Infinity')); // -Infinity
6067 * </code></div>
6168 */
6269/**
@@ -66,7 +73,11 @@ p5.prototype.float = function(str) {
6673 */
6774p5 . prototype . int = function ( n , radix ) {
6875 radix = radix || 10 ;
69- if ( typeof n === 'string' ) {
76+ if ( n === Infinity || n === 'Infinity' ) {
77+ return Infinity ;
78+ } else if ( n === - Infinity || n === '-Infinity' ) {
79+ return - Infinity ;
80+ } else if ( typeof n === 'string' ) {
7081 return parseInt ( n , radix ) ;
7182 } else if ( typeof n === 'number' ) {
7283 return n | 0 ;
@@ -252,6 +263,8 @@ p5.prototype.unchar = function(n) {
252263 * print(hex(255)); // "000000FF"
253264 * print(hex(255, 6)); // "0000FF"
254265 * print(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ]
266+ * print(Infinity); // "FFFFFFFF"
267+ * print(-Infinity); // "00000000"
255268 * </code></div>
256269 */
257270/**
@@ -266,6 +279,9 @@ p5.prototype.hex = function(n, digits) {
266279 return n . map ( function ( n ) {
267280 return p5 . prototype . hex ( n , digits ) ;
268281 } ) ;
282+ } else if ( n === Infinity || n === - Infinity ) {
283+ var c = n === Infinity ? 'F' : '0' ;
284+ return c . repeat ( digits ) ;
269285 } else if ( typeof n === 'number' ) {
270286 if ( n < 0 ) {
271287 n = 0xffffffff + n + 1 ;
0 commit comments