# datatype conversion

**URL:** <https://forum.kx.com/t/datatype-conversion/11144>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [July 27, 2016, 5:03pm UTC](https://forum.kx.com/t/datatype-conversion/11144 "2016-07-27T17:03:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xinyu\_gai](https://avatars.discourse-cdn.com/v4/letter/x/3bc359/32.png) [@xinyu\_gai](https://forum.kx.com/u/xinyu_gai)\
**Post date:** [July 27, 2016, 5:03pm UTC](https://forum.kx.com/t/datatype-conversion/11144/1 "2016-07-27T17:03:00Z")

</div>

Hi there,

I happened to find a interesting problem when dealing with type conversion. Please see my code below (result marked in red)

(2 xexp 60)- (2 xexp 60) + 16f

0f

&nbsp; &nbsp; &nbsp; &nbsp; (2 xexp 10)- (2 xexp 10) + 16f

-16f

(7h$(2 xexp 60))- (7h$(2 xexp 60)) + 16f

0f

(7h$(2 xexp 60))- (7h$(2 xexp 60)) + 16

-16j

&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; (7h$(2 xexp 10))- (7h$(2 xexp 10)) + 16f

-16f

From my understanding, all the code above should return a value of -16 regardless of datatypes. However the first and third line of code obviously return a different result.

It seems that type conversion on big numbers will somehow result in loss of accuracy?

Could someone explain this to me? Hope it is not a stupid mistake made by me.

Thanks,

Xinyu

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [July 27, 2016, 5:11pm UTC](https://forum.kx.com/t/datatype-conversion/11144/2 "2016-07-27T17:11:00Z")

</div>

q)-8!(2 xexp 60)

0x0100000011000000f7efffffffffffaf43

q)-8!(2 xexp 60)+16f

0x0100000011000000f7efffffffffffaf43

ieee754 float \> ~2^53 are not represented precisely.

http://docs.oracle.com/cd/E19957-01/806-3568/ncg\_goldberg.html

---

<div class="post-metadata">

**Author:** ![xinyu\_gai](https://avatars.discourse-cdn.com/v4/letter/x/3bc359/32.png) [@xinyu\_gai](https://forum.kx.com/u/xinyu_gai)\
**Post date:** [July 27, 2016, 5:22pm UTC](https://forum.kx.com/t/datatype-conversion/11144/3 "2016-07-27T17:22:00Z")

</div>

ahh that’s pretty clear, thanks!&nbsp;

Xinyu
