Using Decimal Floating-Point with Intel® C++ Compiler

Intel C++ Compiler 11.x supports decimal floating-point.  For more details about decimal FP, please read /en-us/blogs/2008/03/06/intel-decimal-floating-point-math-library.

It provides three decimal FP types: _Decimal32, _Decimal64 and _Decimal128.  For decimal FP math functions that Intel C++ Compiler currently supports, please read mathimf.h (usually located in C:\Program Files\Intel\Compiler\11.0\nnn\cpp\include on Windows or /opt/intel/Compiler/11.0/nnn/include/ on Linux and Mac OS).

Sample Program

#include <stdio.h>
#include "mathimf.h"
 
int main()
{
 _Decimal32 in1, in2, out1, out2;
 double dResult;
 
 in1  = 7.0;
 in2  = 10000.0;
 out1 = in1 / in2;
 out2 = out1 * in2;
 dResult = out2;
 printf("7.0 / 10000.0 * 10000.0 = %fn", dResult);
 
 in1  = 1.0;
 out1 = sind32(in1);
 printf("sin(1.0) = %fn", (double)out1);
 
 return 1;
}

 

To compile the program using decimal FP, please be sure to define macro __STDC_WANT_DEC_FP__, so that decimal FP math functions are properly declared.

On Windows,

>icl -D__STDC_WANT_DEC_FP__ decimal.c

On Linux,

$ icc -D__STDC_WANT_DEC_FP__ decimal.c -limf


Output

7.0 / 10000.0 * 10000.0 = 7.000000
sin(1.0) = 0.841471
For more complete information about compiler optimizations, see our Optimization Notice.

8 comments

Top

Regarding DFP in c99 mode, please see this thread in the forum: http://software.intel.com/en-us/forums/showthread.php?t=75585&p=1

Tydeman, I would recommend posting your question in the Intel(R) C++ Compiler forum. Article comments may not receive prompt answers. Thanks.

I am trying to compile a program that uses decimal floating-point, but get errors.
Hardware: Intel Pentium 4 is IA-32 mode
O. S.: Linux: Fedora Core 10
Compiler: Intel C Compiler Pro IA-32, Version 11.1, Build 2010/04/14
(I downloaded it from your web site yesterday).
Command line: icc -strict-ansi -std=c99 -fp-model strict -H -O0 -D__STDC_WANT_DEC_FP__ test.c
where test.c has #include <math.h>
The error I get is: .../math.h(1172): error: identifier "_Decimal32" is undefined
extern _Decimal32 acosd32(_Decimal32 x);

Aside: Your <math.h> should have at line 1171:
#if (defined __STDC_WANT_DEC_FP__) && (defined __STDC_DEC_FP__)

So, what command line options do I need to enable decimal FP, along with c99 in strict ANSI mode,
along with strict IEEE-754 mode?

This works perfectly. Thanks.
Are there any plans to add this functionality to the c++ compiler, or would you know if there are any decent alternative libraries worth considering if I need to code in c++?

There is no decimal FP support for C++ so far. I should have noticed you were typing main.cpp. Please use main.c instead.

hi,

I tried this as well, but get many compiler errors (see below). It seems that I must be missing an include file which defines _Decimal32, but have grepped the include directories and can't locate any such reference. Are there any other options I'm missing?

Thanks
Derek

D:\Dev\test3>icl -D __STDC_WANT_DEC_FP__ main.cpp
Intel(R) C++ Compiler Professional for applications running on IA-32, Version 11
.0 Build 20090131 Package ID: w_cproc_p_11.0.072
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.

C:\Program Files (x86)\Intel\Compiler\11.0\072\cpp\Include\mathimf.h(1304): erro
r: identifier "_Decimal32" is undefined
extern _Decimal32 acosd32 (_Decimal32 x);
^

C:\Program Files (x86)\Intel\Compiler\11.0\072\cpp\Include\mathimf.h(1304): erro
r: identifier "_Decimal32" is undefined
extern _Decimal32 acosd32 (_Decimal32 x);
^

Hi Derek,

It looks that you missed the important option -D__STDC_WANT_DEC_FP__. Please try again with the following command line:

icl -D__STDC_WANT_DEC_FP__ main.cpp

The above code does not seem to work, giving the error:

D:\Dev\test3>icl main.cpp
Intel(R) C++ Compiler Professional for applications running on IA-32, Version 11
.0 Build 20090131 Package ID: w_cproc_p_11.0.072
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.

main.cpp
main.cpp(13): error: identifier "_Decimal32" is undefined
_Decimal32 in1, in2, out1, out2;
^

compilation aborted for main.cpp (code 2)

Is there a specific way to enable _Decimal32 under windows?

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.