quotient

There is no quotient function for two double-s? remquo doesn't round to nearest zero. I have to use fmod in indirect way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <iomanip>
#include <cfenv>
#include <cmath>

int main()
{
    std::cout << std::fixed << std::setprecision(2) ;
    
    #pragma STDC FENV_ACCESS ON // standard C99 pragma, ignored by clang++, g++, and msvc++

    std::fesetround( FE_TOWARDZERO ) ; // the first call to fesetround() appears to be supported by all three compilers
    std::cout << "FE_TOWARDZERO: " << 99.0 / 5.0 << ", " << 99.0 / -5.0 << " => " 
              << std::nearbyint( 99.0 / 5.0 ) << ", " << std::nearbyint( 99.0 / -5.0 ) << '\n' ;

    std::fesetround( FE_TONEAREST ) ; // but only the microsoft compiler appears to support subsequent calls
    std::cout << " FE_TONEAREST: "  << 99.0 / 5.0 << ", " << 99.0 / -5.0 << " => " 
              << std::nearbyint( 99.0 / 5.0 ) << ", " << std::nearbyint( 99.0 / -5.0 ) << '\n' ;

    std::fesetround( FE_DOWNWARD ) ; // but only the microsoft compiler appears to support subsequent calls
    std::cout << "  FE_DOWNWARD: " << 99.0 / 5.0 << ", " << 99.0 / -5.0 << " => " 
              << std::nearbyint( 99.0 / 5.0 ) << ", " << std::nearbyint( 99.0 / -5.0 ) << '\n' ;
}

Microsoft: http://rextester.com/RHFS31721
LLVM and GNU: http://coliru.stacked-crooked.com/a/ade0720c6ea98fc1
No, but you can write your own easily enough:

1
2
3
4
inline double iquotient( double n, double d )
{
  return (n - fmod( n, d )) / d;
}

I that what you meant?
Topic archived. No new replies allowed.