ohler55/oj — pull request #55 by yuki24 (2012-12-13 15:50:29+00:00)
Title: Correctly print double numbers like 1.0

For example, when a double number `1.0` is dumped, it'll be just `1` instead of `1.0`. This commit fixes it and now Oj handles the kind of numbers as expected.

I believe this change won't make Oj slow. I tested the performance by looping it 10 million times and the difference(about 10 - 20ms) isn't significant. Here is the code I used to measure the performance:

```c
#include

int main(){
char buf[64];
double d = -3.14; // or something like 1.0 or -3.0
int i;

for(i = 0; i < 10000000; i++) {
sprintf(buf, (d - (long)d) ? "%0.16g" : "%.1f", d);
// or use the next line to make a comparison.
// sprintf(buf, "%0.16g", d);
}

return 0;
}
```
(compiled with `-O0` option, measured using `time` cmd)

And surprisingly, when the value is `1.0` or something like this, it is actually faster than before. I guess this is because `"%.1f"` is faster than `"%0.16g"`.

As you can see, all the tests pass on travis. Also feel free to change the conditional operator to `if ... else ...` if you don't like it.