Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22016

Same calculation on Linux and Windows --> different results

$
0
0

I have coded following algorithm to convert a decimal value into Binary/Hexadecimal etc..

string toFormatFromDecimal(long long t, Format format) {    int digitCount = ceil(log(t) / log((int) format));    string hex = "";    for (int i = 0; i < digitCount; i++) {        long double cur = (long double)t / (long double)(format);        long long ganzzahl = (long long) cur;        long double kommazahl = cur - ganzzahl;        hex += digits[(long long) (kommazahl * format)];        t = ganzzahl;    }    return string(hex.rbegin(), hex.rend());}

I use GCC in linux and Visual Studio c++ compiler on WindowsIt seems that i got different values at the "integer" Division here:

long long ganzzahl = (long long) cur;

Any Idea how this could happen? are there different precissions on Linux and Windows?

ThanksFlorian

--Solution--

string toFormatFromDecimal(long long t, Format format) {    int digitCount = ceil(log(t) / log((int) format));    string hex = "";    for (int i = 0; i < digitCount; i++) {        hex += digits[(int) (t%format)];        t = t/format;    }    return string(hex.rbegin(), hex.rend());}

Viewing all articles
Browse latest Browse all 22016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>