Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7942 Discussions

Quadruple precision in a C/C++ programme

jpelaez
Beginner
1,087 Views
Hi

I am trying to use qudruple precision on a C/C++ programme using the extended option of the Compiler but I get problems. The following code 

#include
#include
#include

void get_half_pi(long double);

int main(int argc, char *argv[])
{
_Quad Pi=3.14159265358979323846q, zz;
char buf[50];
get_half_pi(Pi);

printf("\\n C++ version:");

printf("\\n Pi = %23.20Lf %032llx\\n", (long double)Pi, Pi);

fflush(stdout);
printf("\\n");

zz = __atanq(1.0q);

return 0;

}

give me a problem in the sentence zz = __atanq(1.0q). I am using the compiler flag:
-Qoption,cpp,--extended_float_type
The compiler is able to compile and link the programme and it produce an .exe file. However, in the execution the programme experiences a crash in that sentence because __atanq is unknown. Please, would anybody give me a solution to this problem?

I am working in a Windows 7 machine.

Thanks a lot.

0 Kudos
7 Replies
jpelaez
Beginner
1,087 Views
Well:

I discovered how to avoid the problem. It was very easy: I had to declare the function
_Quad __atanq(_Quad x)
and the programme runs !!!
These are the goods news.

Now  the bad news: there is no way to know what is stored in the variable
zz = __atanq(1.0q);
I tried to obtain the value of zz with _gcvt  but it does not work. I obtained the same result than in double precision.
Please, would anybody tell me how to obtain a real quadruple precison number?

Thanks again.

0 Kudos
jpelaez
Beginner
1,087 Views
TimP:

thanks a lot for your answer. Unfortunately the printf (and alike functions) are not able to manage the _Quad type introduced by Intel in the C/C++ compiler. You can convert the _Quad to a double, but in such a case you loss the information that is inside the _Quad, becasue the diference between the

Regarding to write the routine that convert a _Quad number in a string of chars, I have no idea of the characteristics of the _Quad type and is impossible to me to do it. I though that perhaps Intel has some tool dan can be used.

Finally, how to disply the _Quad number in hexadecimal format? I do not know if it is possible.

Thanks again. Jesus
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,087 Views
Have you tried adding _Quad type to the << operator list in std::cout (this is in ostream)?

Jim Dempsey
0 Kudos
TimP
Honored Contributor III
1,087 Views
In order to display hex, you might store into a union including a quad and an int or long long int array.  Surely at least printf() can handle the hex display of the ints.
0 Kudos
jpelaez
Beginner
1,087 Views
Jim:

thanks a lot for your suggestion. I did not try it because the programme where we need quadruple precision is enterely written in C. However, I will follow your idea in order to see if it works. I will tell you. Thanks again. Jesus
0 Kudos
jpelaez
Beginner
1,087 Views
Tim:

I will try your suggestion. I will tell you if I have success. Thanks. Jesus
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,087 Views
...the programme where we need quadruple precision is enterely written in C. 

The problem is you do not have a %qf (quad float) format capability. This will require you to create your own convert to string function:

    char* Quad2string(char* fmt, _Quad x);

Where fmt is "%[flags][width][.precision]qtype"
and type is e, E, f, g, G, a, A

IOW same as what you might guess a proper format would be expressed using "q" as _Quad type modifier. Or select "ll" lower case el, twice  for twice long. Note, "%llf" in printf is typically "double" not "long long".

  printf("Result = %s\n", Quad2string("%25.3qf", Result); // or "%25.3llf"

I leave it up to you to either write the function or search the internet for code someone else has written.
Look at:

http://sourceforge.net/p/qpfloat/mercurial/ci/393210c0cefbf1e445bb4ab598db4de984699e0e/tree/

This project is for emulating quad precision, and it contains a convert to string. This may have some useful code to read/use.

Jim Dempsey
0 Kudos
Reply