# Floating point division not working

**URL:** <https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845>\
**Category:** CUDA Programming and Performance\
**Created:** [November 7, 2011, 2:40am UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845 "2011-11-07T02:40:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![0000a6](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@0000a6](https://forums.developer.nvidia.com/u/0000a6)\
**Post date:** [November 7, 2011, 2:40am UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845/1 "2011-11-07T02:40:55Z")

</div>

Good evening! I am new to CUDA.

I am trying to divide two floating type numbers simply by / (division) in kernel. But the result always returns the MAX\_NUM of floating data type.  
In debugging mode, I set breakpoint on the line contains /(division), but program does not stop at breakpoint. No debugging msg feedback too.  
My cuda computing ability is only 1.1. Does anyone meet similar problem? Any input is welcome,

Thanks!

---

<div class="post-metadata">

**Author:** ![njuffa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@njuffa](https://forums.developer.nvidia.com/u/njuffa)\
**Post date:** [November 7, 2011, 8:01am UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845/2 "2011-11-07T08:01:44Z")

</div>

Could you show a self-contained small example where floating-point division does not work? Note that with compute capability 1.1 you are limited to operations on “float”, as “double” requires compute capability \>= 1.3 . What CUDA version are you using?

---

<div class="post-metadata">

**Author:** ![0000a6](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@0000a6](https://forums.developer.nvidia.com/u/0000a6)\
**Post date:** [November 7, 2011, 4:12pm UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845/3 "2011-11-07T16:12:15Z")

</div>

Thanks, njuffa

I am using 4.0. Driver version 260.24

**global** void float\_kernel(float\* iarray, int n){  
// n = 8;  
// Block index  
int bx = blockIdx.x;  
int by = blockIdx.y;

```
// Thread index
int tx = threadIdx.x;
int ty = threadIdx.y;
       
int x = tx+bx * blockDim.x;
int y = ty+by * blockDim.y;

int tid = x + y * blockDim.x * gridDim.x;

float phi[4];
uint Idx1;
uint Idx2;

Idx1 = (tid) % (n-1);
if(tid!=0){
    Idx2 = (n-1-tid)%(n-1);
}
else{
    Idx2 = n-1;
}

phi[tid] = (iarray[Idx1*n + Idx2] - iarray[Idx2*n + Idx2])/iarray[Idx1*n + Idx2];

...

```

}

---

<div class="post-metadata">

**Author:** ![njuffa](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@njuffa](https://forums.developer.nvidia.com/u/njuffa)\
**Post date:** [November 7, 2011, 9:47pm UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845/4 "2011-11-07T21:47:59Z")

</div>

I guess I should have expressed myself more clearly. By “self-contained example code”, I meant code that one can compile with nvcc without needing any additional files and then run the resulting executable, also without needing any additional files.

Please note that CUDA 4.0 requires a driver r270 or higher. If indeed you are really running with r260 drivers as indicated, CUDA 4.0 should fail to even initialize. Please make sure your program checks the return code of every API call and every kernel launch.

---

<div class="post-metadata">

**Author:** ![0000a6](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@0000a6](https://forums.developer.nvidia.com/u/0000a6)\
**Post date:** [November 8, 2011, 3:19am UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845/5 "2011-11-08T03:19:16Z")

</div>

> [@](#):
>
> I guess I should have expressed myself more clearly. By “self-contained example code”, I meant code that one can compile with nvcc without needing any additional files and then run the resulting executable, also without needing any additional files.
> 
> Please note that CUDA 4.0 requires a driver r270 or higher. If indeed you are really running with r260 drivers as indicated, CUDA 4.0 should fail to even initialize. Please make sure your program checks the return code of every API call and every kernel launch.

Sorry, that was my fault. I am using 270.41 driver. Here’s example code(in attachment). I still don’t get the arithmetic part. Thanks for reply. I appreciate a lot.  
[floating\_division.cu](https://forums.developer.nvidia.com/uploads/short-url/9q0NWe7lUoweGxqopL8WJHY6oUk.cu) (2.62 KB)

---

<div class="post-metadata">

**Author:** ![0000a6](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@0000a6](https://forums.developer.nvidia.com/u/0000a6)\
**Post date:** [November 8, 2011, 6:43pm UTC](https://forums.developer.nvidia.com/t/floating-point-division-not-working/24845/6 "2011-11-08T18:43:11Z")

</div>

> [@](#):
>
> I guess I should have expressed myself more clearly. By “self-contained example code”, I meant code that one can compile with nvcc without needing any additional files and then run the resulting executable, also without needing any additional files.
> 
> Please note that CUDA 4.0 requires a driver r270 or higher. If indeed you are really running with r260 drivers as indicated, CUDA 4.0 should fail to even initialize. Please make sure your program checks the return code of every API call and every kernel launch.

Thanks njuffa,

The attachment is working now. That is a stupid mistake. Thank you so much.
