Is this normal or a bug ?

cryptonian sujith.thinkpalm at gmail.com
Mon Jul 24 13:25:17 UTC 2023


On Monday, 3 July 2023 at 08:24:22 UTC, Mehdi wrote:
> Hello, d community! I am currently exploring the possibilities 
> of interoperability between C++ and D. While conducting some 
> tests, I came across an interesting case. Here is the C++ code 
> snippet:
>
> ```cpp
> float float_test(float x, float y){
>   return x+y;
> }
> ```
>
> And here is the corresponding D code:
>
> ```d
> extern (C++) float float_test(float x, float y);
> {
>   assert(10.1 + 20.6 == float_test(10.1, 20.6));
> }
> ```
>
> Unfortunately, the assert statement fails in this case. I'm 
> wondering if this discrepancy is due to the different float 
> representations, a bug, or if I'm doing something wrong. Any 
> insights would be greatly appreciated!

The difference in the assert statement could be because of the 
different float representations used in C++ and D. C++ and D 
might employ different floating-point models, leading to minor 
precision differences in arithmetic operations. To resolve this, 
consider using data types or libraries that ensure consistent 
float representations across both languages.
I learned this during my probation time in the organization, a <a 
href=“https://thinkpalm.com/technologies/artificial-inteligence/”>machine learning and AI services provider</a>. Such programs are very rare I guess.


More information about the Digitalmars-d mailing list