Well, that particular case won't unless the tolerance (ε) is very large, as int(0.999) is 0. ;-) More generally, it is, of course, possible, although when it happens will be dependent on the details of the C compiler and compiler options used to build a particular installation of Perl. Alas, this means that it's possible that different Perl installations on a given platform, e.g., ActiveState and Strawberry Perl on Windows, could yield different results.
Given your last statement, "false positives would not have any adverse impact if they only result into action that ensures that $x does not contain a decimal component." you may want to tell us why you're interested in this test, at all. It may be superfluous.
Information about American English usage here and here. Floating point issues? Please read this before posting. — emc
| [reply] |
Ok, i'll try to give a simple explanation. I was drawing a graph with GD::Graph and would like to restrict the the y-ticks so they only get drawn on values like these: 1, 1.5, 2, 2.5, etc. The number of ticks was pre-set.
I've since gone another way that dispenses with this completely, but still thought it would be something nice to meditate over, especially as i couldn't find a solution that didn't fall afoul any of these:- shooting with cannons at flies
- incredibly hackish
- requires a lot of code
- comes with a lot of situations where it fails
I was hoping i'd missed something and someone would point out some inbuilt "has_decimal" function in Perl or something, but apparently no such thing exists.
| [reply] |
There are algorithms out there to find "nice" scales for graphs; I'd suggest one of them. You can find one routine to do so here. It's from the Griffiths and Hill archive at Carnegie-Mellon's StatLib site. More may be found here or at CGAL.
Another is from the Graphics Gems web site.
Information about American English usage here and here. Floating point issues? Please read this before posting. — emc
| [reply] |