# Double vs. Float

**URL:** <https://forums.developer.nvidia.com/t/double-vs-float/76796>\
**Category:** CUDA Programming and Performance\
**Created:** [June 20, 2019, 6:33pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796 "2019-06-20T18:33:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbagies](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tbagies](https://forums.developer.nvidia.com/u/tbagies)\
**Post date:** [June 20, 2019, 6:33pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/1 "2019-06-20T18:33:04Z")

</div>

I write code in CUDA by using Float and then by using Double as the data type. The output result is slightly different from these two data types. Also, the output result is different when I write the code in C. Is there any reason for having different output when changing the data type in CUDA?

---

<div class="post-metadata">

**Author:** ![Robert\_Crovella](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/robert_crovella/32/14043_2.png) [@Robert\_Crovella](https://forums.developer.nvidia.com/u/Robert_Crovella)\
**Post date:** [June 20, 2019, 8:28pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/2 "2019-06-20T20:28:28Z")

</div>

float and double will often produce slightly different results on other platforms besides GPU. You should probably learn more about what these datatypes mean for calculations in C/C++ in general.

There are often differences between host and device floating-point calculations. There may be a lot of reasons for this, from user error, to library implementation differences, to characteristics of floating point calculations (order of operations) when considered in a parallel environment. You can find many questions asking about such differences with a bit of searching.

---

<div class="post-metadata">

**Author:** ![tera](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tera](https://forums.developer.nvidia.com/u/tera)\
**Post date:** [June 20, 2019, 8:30pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/3 "2019-06-20T20:30:51Z")

</div>

No, there is no reason for the results being different. The “double” data type was just invented as a simple means to [slow down floating point computations by a factor anywhere between 2 and 32](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#arithmetic-instructions). But somehow the hardware designers got it all wrong and introduced tiny incompatibilities that no-one has ever bothered to track down to their origin.

You may have more luck by dropping “double” altogether and exclusively using “float” only, and achieving the slowdown by some other means, like extra empty loops causing the desired delay.

---

<div class="post-metadata">

**Author:** ![cbuchner1](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/cbuchner1/32/14168_2.png) [@cbuchner1](https://forums.developer.nvidia.com/u/cbuchner1)\
**Post date:** [June 21, 2019, 3:06pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/4 "2019-06-21T15:06:32Z")

</div>

my sarcasm detector just overflowed after reading tera’s post.

---

<div class="post-metadata">

**Author:** ![markus.louw](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@markus.louw](https://forums.developer.nvidia.com/u/markus.louw)\
**Post date:** [April 22, 2023, 1:00pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/5 "2023-04-22T13:00:32Z")

</div>

tera’s answer will cause another space shuttle disaster one day

---

<div class="post-metadata">

**Author:** ![cbuchner1](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/cbuchner1/32/14168_2.png) [@cbuchner1](https://forums.developer.nvidia.com/u/cbuchner1)\
**Post date:** [April 27, 2023, 2:36pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/6 "2023-04-27T14:36:23Z")

</div>

to be fair, Space Shuttle never had a disastrous software issue. It was Ariane 5 during its maiden flight that had some kind of numeric overflow.

---

<div class="post-metadata">

**Author:** ![markus.louw](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@markus.louw](https://forums.developer.nvidia.com/u/markus.louw)\
**Post date:** [April 27, 2023, 2:47pm UTC](https://forums.developer.nvidia.com/t/double-vs-float/76796/7 "2023-04-27T14:47:47Z")

</div>

not yet lol… but there was a satellite that crashes due to units od measurement differenc3
