Skip to content

Instantly share code, notes, and snippets.

@mathiasbynens
Created August 18, 2011 10:48
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mathiasbynens/1153826 to your computer and use it in GitHub Desktop.
Save mathiasbynens/1153826 to your computer and use it in GitHub Desktop.
Fun with v8’s Number#toString bug
var number = 0,
increment = 0.00000000000001, // smallest value that makes a difference
result,
matches,
match;
for (; number < 100; number += increment) {
result = number.toString(33);
matches = result.match(/[a-z]+/g) || [];
match = matches.indexOf('wtf');
if (match > -1) {
console.log('(' + number + ').toString(33).match(/[a-z]+/g)[' + match + ']; // ' + matches[match]);
}
}
@mathiasbynens
Copy link
Author

See http://code.google.com/p/v8/issues/detail?id=1627.

// What V8 developers thought when @eboyjr discovered this bug:
(6.499999999999994e-13).toString(33).match(/[a-z]+/g)[10]; // 'heh'
(1.1399999999999974e-12).toString(33).match(/[a-z]+/g)[109]; // 'wut'
(6.299999999999994e-13).toString(33).match(/[a-z]+/g)[244]; // 'aha'
(1.592e-11).toString(33).match(/[a-z]+/g)[127]; // 'huh'
(5.870000000000059e-12).toString(33).match(/[a-z]+/g)[39]; // 'wat'
(1.1536999999997645e-10).toString(33).match(/[a-z]+/g)[81]; // 'oops'
(2.2500000000000015e-12).toString(33).match(/[a-z]+/g)[112]; // 'wtf'
(6.514e-11).toString(33).match(/[a-z]+/g)[238]; // 'meh'
(1.6374489999831224e-8).toString(33).match(/[a-z]+/g)[226]; // 'ohsnap'
(1.6863000000001896e-10).toString(33).match(/[a-z]+/g)[104]; // 'rofl'
(1.648000000000158e-10).toString(33).match(/[a-z]+/g)[221]; // 'noob'
(1.3700999999999292e-10).toString(33).match(/[a-z]+/g)[132]; // 'pwnt'
(4.705000000000126e-11).toString(33).match(/[a-z]+/g)[180]; // 'fuck'
(4.3871999999970926e-10).toString(33).match(/[a-z]+/g)[176]; // 'shiii'
(1.711560000005535e-9).toString(33).match(/[a-z]+/g)[36]; // 'aargh'
(1.4310999999999794e-10).toString(33).match(/[a-z]+/g)[88]; // 'dude'
(1.202499999999791e-10).toString(33).match(/[a-z]+/g)[204]; // 'ffuu'

~~ (6.200000000000147e-11).toString(33).match(/[a-z]+/g)[180]

@dsamarin
Copy link

/* pardon  */ (8.852546999924978e-8).toString(36).match(/[a-z]{5,}/g)[1] + " me";
/* shame   */ (8.47487600005451e-8).toString(36).match(/[a-z]{5,}/g)[0] + " on me";
/* orgasm  */ (101/49680).toString(33).match(/[a-z]{6,}/g)[20];
/* newton  */ (341/27650).toString(33).match(/[a-z]{6,}/g)[34] + " would be disappointed";
/* frowns  */ (1/4503599624754323).toString(36).match(/[a-z]{6,}/g)[0];
/* prepare */ "I didn't " + (Math.PI / 32954).toString(33).match(/[a-z]{6,}/g)[8] + " for this.";

~~ (761/708).toString(35).slice(1073,1079)

@tomasdev
Copy link

/* I */ (1.2967999999998688e-10).toString(33).match(/[a-z]+/g)[185] /* this */

@aredridel
Copy link

897217487244305.0.toString(33) + " is super fun"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment