like Nick Holmes' approach, very elegant, but Log or Log2 uses double as input type, which has not enough bits, when we stick to the chess board.
Since a chessboard has 64 tiles, we would need an unsigned long (64 bit) to capture the complete number space. double has also 64 bit, but reserves some for the exponent, introducing a small, but not negligible error when coming closer to the last tiles. double precision is 15-17 digits, but we need up to 20 digits to represent such big numbers.
E.g. if you are just a few (lets say 90, to be safe - we are already in the quadrillions to give some relation) grains over the 63th tile the error would result in giving you 63 instead of 64.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
like Nick Holmes' approach, very elegant, but Log or Log2 uses
double
as input type, which has not enough bits, when we stick to the chess board.Since a chessboard has 64 tiles, we would need an unsigned long (64 bit) to capture the complete number space.
double
has also 64 bit, but reserves some for the exponent, introducing a small, but not negligible error when coming closer to the last tiles. double precision is 15-17 digits, but we need up to 20 digits to represent such big numbers.E.g. if you are just a few (lets say 90, to be safe - we are already in the quadrillions to give some relation) grains over the 63th tile the error would result in giving you 63 instead of 64.