log2 buggy or is a real thing?

2012-04-04 Thread Jonathan M Davis
This progam: import std.math; import std.stdio; import std.typetuple; ulong log2(ulong n) { return n == 1 ? 0 : 1 + log2(n / 2); } void print(ulong value) { writefln(%s: %s %s, value, log2(value), std.math.log2(value)); } void main() { foreach(T; TypeTuple!(byte,

Re: log2 buggy or is a real thing?

2012-04-04 Thread bearophile
Jonathan M Davis: This progam: import std.math; import std.stdio; import std.typetuple; ulong log2(ulong n) { return n == 1 ? 0 : 1 + log2(n / 2); } void print(ulong value) { writefln(%s: %s %s, value, log2(value), std.math.log2(value)); } void

Re: log2 buggy or is a real thing?

2012-04-04 Thread bearophile
Do you know why is this program: import std.stdio; void main() { real r = 9223372036854775808UL; writefln(%1.19f, r); } Printing: 9223372036854775807.800 Instead of this? 9223372036854775808.000 Bye, bearophile

Re: log2 buggy or is a real thing?

2012-04-04 Thread Don Clugston
On 04/04/12 13:40, bearophile wrote: Jonathan M Davis: This progam: import std.math; import std.stdio; import std.typetuple; ulong log2(ulong n) { return n == 1 ? 0 : 1 + log2(n / 2); } void print(ulong value) { writefln(%s: %s %s, value, log2(value),

Re: log2 buggy or is a real thing?

2012-04-04 Thread Timon Gehr
On 04/04/2012 05:15 PM, Don Clugston wrote: I don't think so. For 80-bit reals, every long can be represented exactly in an 80 bit real, as can every ulong from 0 up to and including ulong.max - 1. The only non-representable built-in integer is ulong.max, which (depending on rounding mode) gets

Re: log2 buggy or is a real thing?

2012-04-04 Thread Timon Gehr
On 04/04/2012 01:46 PM, bearophile wrote: Do you know why is this program: import std.stdio; void main() { real r = 9223372036854775808UL; writefln(%1.19f, r); } Printing: 9223372036854775807.800 Instead of this? 9223372036854775808.000 Bye,

Re: log2 buggy or is a real thing?

2012-04-04 Thread Don Clugston
On 04/04/12 18:53, Timon Gehr wrote: On 04/04/2012 05:15 PM, Don Clugston wrote: I don't think so. For 80-bit reals, every long can be represented exactly in an 80 bit real, as can every ulong from 0 up to and including ulong.max - 1. The only non-representable built-in integer is ulong.max,

Re: log2 buggy or is a real thing?

2012-04-04 Thread Don Clugston
On 04/04/12 13:46, bearophile wrote: Do you know why is this program: import std.stdio; void main() { real r = 9223372036854775808UL; writefln(%1.19f, r); } Printing: 9223372036854775807.800 Instead of this? 9223372036854775808.000 Bye, bearophile