Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

g++ 4.9.2: Problematic output of fmod (long double, long double)

10 views
Skip to first unread message

alex.v...@gmail.com

unread,
Feb 11, 2016, 4:13:36 AM2/11/16
to
It seems that output of fmod (long double, long double) in this test is problematocs.
Any suggestions?

See below.


> g++ --version
g++ (GCC) 4.9.2

> uname -srvmpio
CYGWIN_NT-6.1 1.7.34(0.285/5/3) 2015-02-04 12:12 i686 unknown unknown Cygwin


> g++ test1.cpp
// No errors, no warnings


> ./a.exe

l1 = 4294967296
l2 = 72057594037927934
l3 = 4294967294

d1 = 4294967296
d2 = 72057594037927934
d3 = 0 // Expected 4294967294


// -------- Program test1. cpp --------
#include <iostream>
#include <iomanip>
#include <cmath>

int main (int argc, char** argv)
{

long long l1 = 4294967296;
long long l2 = 72057594037927934;
long long l3 = l2 % l1;

long double d1 = static_cast<long double>(l1);
long double d2 = static_cast<long double>(l2);
long double d3 = fmod (d2, d1);

std::cout << "l1 = " << l1 << std::endl;
std::cout << "l2 = " << l2 << std::endl;
std::cout << "l3 = " << l3 << std::endl;

std::cout << std::endl;
std::cout << "d1 = " << std::setprecision(18) << d1 << std::endl;
std::cout << "d2 = " << std::setprecision(18) << d2 << std::endl;
std::cout << "d3 = " << std::setprecision(18) << d3 << std::endl;

return 0;

}
// -----------------------
0 new messages