Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.

Quad-precision (_Quad) data type

safris
Novice
817 Views
 

I have been trying to work with Quad-precision floats. I have the following code, and it is returning unexpected results.

#include <stdio.h>
#include <math.h>

int print(const char *label, _Quad r) {
  int prec = 20;
  int width = 46;
  char buf[128];

  int n = quadmath_snprintf(buf, sizeof buf, "%+-#*.36Qe", width, r);
  printf ("%s: %s\n", label, buf);
  return 0;
}

int main () {
  _Quad x = 3.14159265358979323846264338327950288q;
  print("value", x);
  print("log", logq(x));
  print("log10", log10q(x));
  print("cos", cosq(x));
  print("sin", sinq(x));
  print("sqrt", sqrtq(x));
}

This program returns the following results:

value: +3.141592653589793238462643383279502797e+00   
log: +7.644623500000000000000000000000000000e+07   
log10: -6.174980530000000000000000000000000000e+08   
cos: +0.000000000000000000000000000000000000e+00   
sin: +0.000000000000000000000000000000000000e+00   
sqrt: -1.994699018000000000000000000000000000e+09   

It looks like the quad-precision literal is being interpreted correctly. However, the functions logq, log10q, cosq, sinq and sqrtq are returning incorrect results.

The only directions I've found regarding Intel's _Quad type is here.

I am compiling this code on MacOS with:

icc -fPIC -wd1572 -Qoption,cpp,--extended_float_type -Wconversion -lquadmath -L/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 test.c

Am I using the quad-precision math functions correctly?

Also, I have tried to use the function pattern as described in this post.

 Quadruple precision analogs of libm functions have '__' prefix (double underscore) and 'q' suffix."

However, this results in NaN returned for all functions.

0 Kudos
1 Solution
AbhishekD_Intel
Moderator
805 Views

Hi Safris,

 

Yes, your implementation for Quadruple Precision is correct.

But there is a small addition you need to do in your code. Just add quadmath.h header in your file and execute with the same command you tried earlier you will get the correct result.

 

Please refer to the below screenshot for more details and do let us know if you faced any issues.

 

Screenshot_cp (347).jpg

 

Warm Regards,

Abhishek

 

View solution in original post

3 Replies
AbhishekD_Intel
Moderator
806 Views

Hi Safris,

 

Yes, your implementation for Quadruple Precision is correct.

But there is a small addition you need to do in your code. Just add quadmath.h header in your file and execute with the same command you tried earlier you will get the correct result.

 

Please refer to the below screenshot for more details and do let us know if you faced any issues.

 

Screenshot_cp (347).jpg

 

Warm Regards,

Abhishek

 

safris
Novice
781 Views

Thank you for the prompt response @AbhishekD_Intel  Your solution is right on! For completeness, I'll post my working code and compile flags for others that stumble on this issue.

#include <stdio.h>
#include <math.h>
#include <quadmath.h>

int print(const char *label, _Quad r) {
  int prec = 20;
  int width = 46;
  char buf[128];

  int n = quadmath_snprintf(buf, sizeof buf, "%+-#*.36Qe", width, r);
  printf ("%s: %s\n", label, buf);
  return 0;
}

int main () {
  _Quad x = 3.14159265358979323846264338327950288q;
  print("value", x);
  print("log", logq(x));
  print("log10", log10q(x));
  print("cos", cosq(x));
  print("sin", sinq(x));
  print("sqrt", sqrtq(x));
}

 

On MacOS with icc (ICC) 19.1.2.258 20200623

icc -fPIC -wd1572 -Qoption,cpp,--extended_float_type -Wconversion -lquadmath -I/usr/local/Cellar/gcc/10.2.0/lib/gcc/10/gcc/x86_64-apple-darwin19/10.2.0/include -L/usr/local/Cellar/gcc/10.2.0/lib/gcc/10 test.c

 

AbhishekD_Intel
Moderator
773 Views

Thank you for the confirmation, we will no longer monitor this thread as your issue is resolved.

Please post a new thread you have any issues.


Warm Regards,

Abhishek


Reply