Weirdness [Please Read]

Herr Witten lingwitt at bellsouth.net
Wed Feb 25 17:12:15 CET 2004


> mpf_t array[4];
> mpf_init(array[0]);
> mpf_init(array[1]);
> mpf_init(array[2]);
> mpf_init(array[3]);
> mpf_init(array[4]);

On 25 Feb 2004, at 7:06 AM, Torbjorn Granlund wrote:
> This sort of issues is covered in any beginner's C book.
> Please read such a book before asking for help debugging your code.

Yes, I already knew the error, I just didn't know that I had made it; 
we all make mistakes. Thanks to the guys who sent worthwhile responses.

On 25 Feb 2004, at 3:10 PM, Brian Hurt wrote:

>
>> //mpf_ptr p = *array;
>
> I think you want:
>     mpf_ptr p = array;

That's what I did at first, but I got main.cpp:12: error: cannot 
convert `__mpf_struct (*)[1]' to `__mpf_struct*' in initialization.

So, it turns out that mpf_t is an array of one element, so, we get the 
first item of it instead with either

mpf_ptr p = *array;

or

mpf_t* p = array;

Here we go:

mpf_t array[4];
mpf_init(array[0]);
mpf_init2(array[1], 1000000);
mpf_init(array[2]);
mpf_init2(array[3], 1000000);

mpf_ptr p = *array;

for (int index = 0; index < 4; index++)
{
     mpf_set_d(p++, 100);
     //if it were mpf_t* p = array;
     //the it would be
     //mpf_set_d(*(p++), 100);
}

mpf_add(array[3], array[1], array[2]);

mpf_out_str(stdout, 10, 10, array[3]);

In any case, the precision is not uniform throughout the elements, 
which was said to be improper
in another thread. Why is that improper?

P.S.
I know that this question may seem trivial to you, but I have not 
created any library like this, and it is hard to find answers to 
questions like these in C books. I am actually quite well versed in C 
for my background. In other words,
there is always a place to start learning, and this is as good as any. 
Surely it would not hurt to help someone.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2840 bytes
Desc: not available
Url : /list-archives/gmp-discuss/attachments/20040225/2d52d624/attachment.bin


More information about the gmp-discuss mailing list