I'm using a JavaScript library called phpjs The goal is to create functions that mimic how PHP handles them.
Here's one function in particular: http://phpjs.org/functions/is_float:442
I've written a couple of test-cases and all is as expected. However, all breaks when I try this:
document.write(is_float(16.0x00000000));
No true or false hits the screen, just empty white space. Why is this?
While I'm at it, in that function, it says return !!(mixed_var % 1);
What is the double !! for? I've never encountered this before. Leaving one out in the source code gets the exact same result for the following test-cases. Any case I might be forgetting?
document.write(is_float(186.31));document.write('<br>');
document.write(is_float("186.31"));document.write('<br>');
document.write(is_float("number"));document.write('<br>');
document.write(is_float("16.0x00000000"));document.write('<br>');
document.write(is_float("16"));document.write('<br>');
document.write(is_float(16));document.write('<br>');
document.write(is_float(0));document.write('<br>');
document.write(is_float("0"));document.write('<br>');
document.write(is_float(0.0));document.write('<br>');
document.write(is_float("0.0"));document.write('<br>');
document.write(is_float("true"));document.write('<br>');
document.write(is_float(true));document.write('<br>');
document.write(is_float("false"));document.write('<br>');
document.write(is_float(false));document.write('<br>');
EDIT: about the 0.0 issue, this cannot be fixed. Check the documentation:
//1.0 is simplified to 1 before it can be accessed by the function, this makes //it different from the PHP implementation. We can't fix this unfortunately.
It appears that this is just something that JavaScript does, on it's own. The programmer has no control over this.