# Decimal Floating-Point Math Library newbie question

## Decimal Floating-Point Math Library newbie question

Hi all:

I'm trying use/understand the Decimal Floating-Point Library. After

compiling with success the libraries, the tests and the examples, as a

first attempt I try a light addition to the example in the file

main.c_011:

First, adding a new set of variables:

Decimal128 a, b, c;

After the sentence:

printf ("TEST CASE 1 FOR __bid128_mul 011 () PASSED
");

I initiate the new variables (as in the example) and try an addition:

c.w[HIGH_128W] = 0xbaddbaddbaddbaddull; c.w[LOW_128W] =

0xbaddbaddbaddbaddull;

a.w[HIGH_128W] = 0x3040000000000000ull; a.w[LOW_128W] =

0x0000000000000002ull; // a = 2

b.w[HIGH_128W] = 0x3040000000000000ull; b.w[LOW_128W] =

0x0000000000000003ull; // b = 3

c = __bid128_add (a, b);

In this last sentence, I obtain an C2440 error:

error: cannot convert from 'int' to 'Decimal128'

I'm using the MS Visual Studio 2008 compiler Standard Edition under

Windows XP.

Any help or suggestion wold be much appreciated.

Thanks in advance

4 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

I think all you need is a line in decimal.h, with:

extern Decimal128 __bid128_add (Decimal128, Decimal128);

If you want to be able toprint the result, add also:

extern __bid128_to_string (char *, Decimal128);

and then in main.c add:

Decimal128 a, b, c;
char str[128];

c = __bid128_add (a, b);
__bid128_to_string (str, c);
printf ("c = %s
", str);

So you need to list (in decimal.h or main.c) all the library functions you are using. A complete list is in LIBRARY/bid_functions.h, but some editing will be necessary if you wish to include all.

Thanks -

Thanks for your input.

That works, but the result is: c = +5E+0

How can I get a decimal (not scientific/engineering) format?

Thanks in advance.

The library supports conversions from decimal to string format using only the scientific format (however, for the opposite conversion the exponent is optional). Eventually, the printf function should support decimal types. Because that is not the case yet, one way around this is to convert the decimal value to binary format with functions available in the library (e.g. to float, double, or long double format if supported) and to print the result with printf. Note that conversions from decimal to binary formatmay incur a rounding error if the conversion is not exact. However, the result of the decimal-to-binary conversion is correctly rounded in the IEEE sense so the rounding error will be minimal.

Thanks -