Diablo-D3 / DiabloMiner

OpenCL miner for Bitcoin
https://bitcointalk.org/index.php?topic=1721.0
GNU General Public License v3.0
538 stars 217 forks source link

Avoid float comparison bugs. #55

Closed jakerr closed 11 years ago

jakerr commented 11 years ago

I was getting this exception:

[2/11/13 8:36:38 PM] Started
[2/11/13 8:36:38 PM] Connecting to: http://localhost:8332/
[2/11/13 8:36:38 PM] Using NVIDIA CUDA OpenCL 1.1 CUDA 4.2.1
[2/11/13 8:36:38 PM] Added GeForce GTX 560 Ti (#1) (8 CU, local work size of 1024)
[2/11/13 8:36:38 PM] ERROR: Failed to allocate blank buffer
DiabloMiner: An error occurred while starting the application.

I tracked it down to the the check for platform that was taking the wrong path:

if (platform_version == 1.1) {
// this is probably what is intended to run
} else {
// this is what is actually run
}

It's easy to forget to put an 'f' after a float literal, which will cause comparison with a float to return false.

This could have obviously been fixed more simply by changing the above to

if (platform_version == 1.1f) { /*...*/ }

But it's an easy mistake to make, and you won't know until run-time that you've made it so thought this would be the safer way. If you'd like to address the issue another way, like using a String "1.1" feel free to close the request and fix however you'd like.

Thanks!