Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > gnu.g++.help > #332

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

Newsgroups gnu.g++.help
Date 2016-02-11 01:13 -0800
Message-ID <e2ad6beb-2b03-4738-a2a4-c064d95ecf98@googlegroups.com> (permalink)
Subject g++ 4.9.2: Problematic output of fmod (long double, long double)
From alex.vinokur@gmail.com

Show all headers | View raw


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;

}
// -----------------------

Back to gnu.g++.help | Previous | Next | Find similar


Thread

g++ 4.9.2: Problematic output of fmod (long double, long double) alex.vinokur@gmail.com - 2016-02-11 01:13 -0800

csiph-web