Dear Alexel,<br>even with your suggested correction, it gives exactly the same error.<br>I think the problem lies in some way in my assignment operator, when I use the overloaded operator= of numeric.<br><br><br>rinterval& rinterval::operator=(const rinterval &rhs)<br>
{<br>
if (this == &rhs) return *this; // Same object?<br>
else<br>
{<br>
try<br>
{<br>
this->min=rhs.min; <br>// I expect here the assignment operator of numeric to destroy the old instance of min and create a new one<br>// but it seems like he simply slices rhs.min to fit into min, therefore losing some information about the precision<br>
// of rhs.min; I tried also this using the CLN library and, if I define min as a cl_R and rhs.min is a cl_LF, when I come to this point <br>// it seems like the precision of min doesn't change, even if the precision of rhs.min is bigger;<br>
// I would like the assignment operator to destroy the former istance of min and build a new one, but it doesn't seem to work<br>// I tried calling the destructors explictly, but it doesn't work either.<br>
this->max=rhs.max;<br>
error=rhs.error;<br>
}<br>
catch(std::exception & exc)<br>
{<br>
std:cerr << "Exception" << exc.what() << endl;<br>
}<br>
return *this;<br>
}<br>
}<br><br>Best regards<br>Isaia<br><br><div class="gmail_quote">On Tue, Mar 29, 2011 at 12:00 PM, <span dir="ltr"><<a href="mailto:ginac-list-request@ginac.de">ginac-list-request@ginac.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Send GiNaC-list mailing list submissions to<br>
<a href="mailto:ginac-list@ginac.de">ginac-list@ginac.de</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="https://www.cebix.net/mailman/listinfo/ginac-list" target="_blank">https://www.cebix.net/mailman/listinfo/ginac-list</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:ginac-list-request@ginac.de">ginac-list-request@ginac.de</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:ginac-list-owner@ginac.de">ginac-list-owner@ginac.de</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of GiNaC-list digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. assignment (Nisoli Isaia)<br>
2. Re: assignment (Alexei Sheplyakov)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Mon, 28 Mar 2011 11:33:53 +0200<br>
From: Nisoli Isaia <<a href="mailto:nisoli@mail.dm.unipi.it">nisoli@mail.dm.unipi.it</a>><br>
To: <a href="mailto:ginac-list@ginac.de">ginac-list@ginac.de</a><br>
Subject: [GiNaC-list] assignment<br>
Message-ID: <BANLkTi=<a href="mailto:ebBvqzhPPdPiZGXfKatwgt64%2Bfw@mail.gmail.com">ebBvqzhPPdPiZGXfKatwgt64+fw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Dear all,<br>
I have a problem with Ginac.<br>
I'm sorry if my question seems stupid, but I cannot solve the issue.<br>
<br>
So, I define a new class:<br>
<br>
class rinterval<br>
{<br>
public:<br>
numeric min;<br>
numeric max;<br>
numeric error;<br>
<br>
//Constructor<br>
rinterval();<br>
rinterval(const numeric &, const numeric &, const numeric &);<br>
//Destructor<br>
~rinterval();<br>
//Friend<br>
friend const rinterval dynamic(const rinterval &);<br>
friend std::ostream &operator<< (std::ostream &os, const rinterval<br>
&inter)<br>
{<br>
return os << "[" << inter.min << "," << inter.max <<"], error = " <<<br>
inter.error << endl;<br>
};<br>
rinterval& operator=(const rinterval &rhs);<br>
};<br>
<br>
The involved functions are these<br>
<br>
rinterval::rinterval(const numeric &input1, const numeric &input2, const<br>
numeric &miserr)<br>
{<br>
if (input1>input2)<br>
{<br>
min=input2;<br>
max=input1;<br>
}<br>
else<br>
{<br>
min=input1;<br>
max=input2;<br>
}<br>
error=miserr;<br>
}<br>
<br>
const rinterval dynamic(const rinterval &domain)<br>
{<br>
numeric a="1.47777777777777777777777777779999";<br>
rinterval temp(a*domain.min,a*domain.max,domain.error);<br>
cout << temp;<br>
return temp;<br>
}<br>
<br>
rinterval& rinterval::operator=(const rinterval &rhs)<br>
{<br>
if (this == &rhs) return *this; // Same object?<br>
else<br>
{<br>
try<br>
{<br>
this->min=rhs.min;<br>
this->max=rhs.max;<br>
error=rhs.error;<br>
}<br>
catch(std::exception & exc)<br>
{<br>
std:cerr << "Exception" << exc.what() << endl;<br>
}<br>
return *this;<br>
}<br>
}<br>
<br>
Now, if inside the main I do<br>
<br>
int main (void)<br>
{<br>
numeric a(1,10);<br>
numeric b(2,10);<br>
rinterval inter(a,b,(numeric)0.00001);<br>
inter=dynamic(inter);<br>
cout << inter << endl;<br>
}<br>
<br>
I get the following error:<br>
*** glibc detected *** ./invmeasure.exe: invalid fastbin entry (free):<br>
0x00000000008ec340 ***<br>
======= Backtrace: =========<br>
/lib/libc.so.6(+0x774b6)[0x7f2c9b11a4b6]<br>
/lib/libc.so.6(cfree+0x73)[0x7f2c9b120c83]<br>
/usr/lib/libcln.so.6(+0x6fa0d)[0x7f2c9ad91a0d]<br>
/usr/lib/libcln.so.6(_ZN3cln11print_floatERSoRKNS_20cl_print_float_flagsERKNS_4cl_FE+0x29)[0x7f2c9ad92d39]<br>
/usr/lib/libginac-1.5.so.0(+0x1ddb5b)[0x7f2c9bfbfb5b]<br>
/usr/lib/libginac-1.5.so.0(_ZNK5GiNaC7numeric13print_numericERKNS_13print_contextEPKcS5_S5_S5_j+0x97)[0x7f2c9bfc0857]<br>
/usr/lib/libginac-1.5.so.0(_ZNK5GiNaC7numeric8do_printERKNS_13print_contextEj+0x28)[0x7f2c9bfc0e48]<br>
/usr/lib/libginac-1.5.so.0(_ZNK5GiNaC5basic14print_dispatchERKNS_10class_infoINS_24registered_class_optionsEEERKNS_13print_contextEj+0x18b)[0x7f2c9be6c62b]<br>
/usr/lib/libginac-1.5.so.0(_ZN5GiNaClsERSoRKNS_2exE+0x9e)[0x7f2c9bfe5c2e]<br>
./invmeasure.exe[0x404261]<br>
./invmeasure.exe[0x403808]<br>
/lib/libc.so.6(__libc_start_main+0xfe)[0x7f2c9b0c1d8e]<br>
./invmeasure.exe[0x403439]<br>
======= Memory map: ========<br>
00400000-00407000 r-xp 00000000 08:07 66333<br>
/home/isaia/Dropbox/HTGFL/GN-Comput_inv_1D/codice/invmeasure.exe<br>
00607000-00608000 r--p 00007000 08:07 66333<br>
/home/isaia/Dropbox/HTGFL/GN-Comput_inv_1D/codice/invmeasure.exe<br>
00608000-00609000 rw-p 00008000 08:07 66333<br>
/home/isaia/Dropbox/HTGFL/GN-Comput_inv_1D/codice/invmeasure.exe<br>
008c7000-00909000 rw-p 00000000 00:00 0<br>
[heap]<br>
7f2c94000000-7f2c94021000 rw-p 00000000 00:00 0<br>
7f2c94021000-7f2c98000000 ---p 00000000 00:00 0<br>
7f2c9a8be000-7f2c9a91d000 r-xp 00000000 08:07 1523786<br>
/usr/lib/libgmp.so.3.5.2<br>
7f2c9a91d000-7f2c9ab1c000 ---p 0005f000 08:07 1523786<br>
/usr/lib/libgmp.so.3.5.2<br>
7f2c9ab1c000-7f2c9ab1d000 r--p 0005e000 08:07 1523786<br>
/usr/lib/libgmp.so.3.5.2<br>
7f2c9ab1d000-7f2c9ab1e000 rw-p 0005f000 08:07 1523786<br>
/usr/lib/libgmp.so.3.5.2<br>
7f2c9ab1e000-7f2c9ab20000 r-xp 00000000 08:07 262984<br>
/lib/<a href="http://libdl-2.12.1.so" target="_blank">libdl-2.12.1.so</a><br>
7f2c9ab20000-7f2c9ad20000 ---p 00002000 08:07 262984<br>
/lib/<a href="http://libdl-2.12.1.so" target="_blank">libdl-2.12.1.so</a><br>
7f2c9ad20000-7f2c9ad21000 r--p 00002000 08:07 262984<br>
/lib/<a href="http://libdl-2.12.1.so" target="_blank">libdl-2.12.1.so</a><br>
7f2c9ad21000-7f2c9ad22000 rw-p 00003000 08:07 262984<br>
/lib/<a href="http://libdl-2.12.1.so" target="_blank">libdl-2.12.1.so</a><br>
7f2c9ad22000-7f2c9ae98000 r-xp 00000000 08:07 1549774<br>
/usr/lib/libcln.so.6.0.1<br>
7f2c9ae98000-7f2c9b097000 ---p 00176000 08:07 1549774<br>
/usr/lib/libcln.so.6.0.1<br>
7f2c9b097000-7f2c9b09b000 r--p 00175000 08:07 1549774<br>
/usr/lib/libcln.so.6.0.1<br>
7f2c9b09b000-7f2c9b0a1000 rw-p 00179000 08:07 1549774<br>
/usr/lib/libcln.so.6.0.1<br>
7f2c9b0a1000-7f2c9b0a3000 rw-p 00000000 00:00 0<br>
7f2c9b0a3000-7f2c9b21d000 r-xp 00000000 08:07 262821<br>
/lib/<a href="http://libc-2.12.1.so" target="_blank">libc-2.12.1.so</a><br>
7f2c9b21d000-7f2c9b41c000 ---p 0017a000 08:07 262821<br>
/lib/<a href="http://libc-2.12.1.so" target="_blank">libc-2.12.1.so</a><br>
7f2c9b41c000-7f2c9b420000 r--p 00179000 08:07 262821<br>
/lib/<a href="http://libc-2.12.1.so" target="_blank">libc-2.12.1.so</a><br>
7f2c9b420000-7f2c9b421000 rw-p 0017d000 08:07 262821<br>
/lib/<a href="http://libc-2.12.1.so" target="_blank">libc-2.12.1.so</a><br>
7f2c9b421000-7f2c9b426000 rw-p 00000000 00:00 0<br>
7f2c9b426000-7f2c9b43b000 r-xp 00000000 08:07 262222<br>
/lib/libgcc_s.so.1<br>
7f2c9b43b000-7f2c9b63a000 ---p 00015000 08:07 262222<br>
/lib/libgcc_s.so.1<br>
7f2c9b63a000-7f2c9b63b000 r--p 00014000 08:07 262222<br>
/lib/libgcc_s.so.1<br>
7f2c9b63b000-7f2c9b63c000 rw-p 00015000 08:07 262222<br>
/lib/libgcc_s.so.1<br>
7f2c9b63c000-7f2c9b6be000 r-xp 00000000 08:07 262828<br>
/lib/<a href="http://libm-2.12.1.so" target="_blank">libm-2.12.1.so</a><br>
7f2c9b6be000-7f2c9b8bd000 ---p 00082000 08:07 262828<br>
/lib/<a href="http://libm-2.12.1.so" target="_blank">libm-2.12.1.so</a><br>
7f2c9b8bd000-7f2c9b8be000 r--p 00081000 08:07 262828<br>
/lib/<a href="http://libm-2.12.1.so" target="_blank">libm-2.12.1.so</a><br>
7f2c9b8be000-7f2c9b8bf000 rw-p 00082000 08:07 262828<br>
/lib/<a href="http://libm-2.12.1.so" target="_blank">libm-2.12.1.so</a><br>
7f2c9b8bf000-7f2c9b9a7000 r-xp 00000000 08:07 1523946<br>
/usr/lib/libstdc++.so.6.0.14<br>
7f2c9b9a7000-7f2c9bba6000 ---p 000e8000 08:07 1523946<br>
/usr/lib/libstdc++.so.6.0.14<br>
7f2c9bba6000-7f2c9bbae000 r--p 000e7000 08:07 1523946<br>
/usr/lib/libstdc++.so.6.0.14<br>
7f2c9bbae000-7f2c9bbb0000 rw-p 000ef000 08:07 1523946<br>
/usr/lib/libstdc++.so.6.0.14<br>
7f2c9bbb0000-7f2c9bbc5000 rw-p 00000000 00:00 0<br>
7f2c9bbc5000-7f2c9bbdd000 r-xp 00000000 08:07 262823<br>
/lib/<a href="http://libpthread-2.12.1.so" target="_blank">libpthread-2.12.1.so</a><br>
7f2c9bbdd000-7f2c9bddc000 ---p 00018000 08:07 262823<br>
/lib/<a href="http://libpthread-2.12.1.so" target="_blank">libpthread-2.12.1.so</a><br>
7f2c9bddc000-7f2c9bddd000 r--p 00017000 08:07 262823<br>
/lib/<a href="http://libpthread-2.12.1.so" target="_blank">libpthread-2.12.1.so</a><br>
7f2c9bddd000-7f2c9bdde000 rw-p 00018000 08:07 262823<br>
/lib/<a href="http://libpthread-2.12.1.so" target="_blank">libpthread-2.12.1.so</a><br>
7f2c9bdde000-7f2c9bde2000 rw-p 00000000 00:00 0<br>
7f2c9bde2000-7f2c9c0c1000 r-xp 00000000 08:07 1524595<br>
/usr/lib/libginac-1.5.so.0.2.0<br>
7f2c9c0c1000-7f2c9c2c0000 ---p 002df000 08:07 1524595<br>
/usr/lib/libginac-1.5.so.0.2.0<br>
7f2c9c2c0000-7f2c9c2cc000 r--p 002de000 08:07 1524595<br>
/usr/lib/libginac-1.5.so.0.2.0<br>
7f2c9c2cc000-7f2c9c2cd000 rw-p 002ea000 08:07 1524595<br>
/usr/lib/libginac-1.5.so.0.2.0<br>
7f2c9c2cd000-7f2c9c2cf000 rw-p 00000000 00:00 0<br>
7f2c9c2cf000-7f2c9c2ef000 r-xp 00000000 08:07 262975<br>
/lib/<a href="http://ld-2.12.1.so" target="_blank">ld-2.12.1.so</a><br>
7f2c9c4c3000-7f2c9c4ca000 rw-p 00000000 00:00 0<br>
7f2c9c4ec000-7f2c9c4ef000 rw-p 00000000 00:00 0<br>
7f2c9c4ef000-7f2c9c4f0000 r--p 00020000 08:07 262975<br>
/lib/<a href="http://ld-2.12.1.so" target="_blank">ld-2.12.1.so</a><br>
7f2c9c4f0000-7f2c9c4f1000 rw-p 00021000 08:07 262975<br>
/lib/<a href="http://ld-2.12.1.so" target="_blank">ld-2.12.1.so</a><br>
7f2c9c4f1000-7f2c9c4f2000 rw-p 00000000 00:00 0<br>
7fff794fd000-7fff7951e000 rw-p 00000000 00:00 0<br>
[stack]<br>
7fff795c7000-7fff795c8000 r-xp 00000000 00:00 0<br>
[vdso]<br>
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0<br>
[vsyscall]<br>
<br>
I don't understand why, isn't the destruction of the old instances of min<br>
and max done by the assignment operator for the type numeric?<br>
<br>
Thank you in advance<br>
Isaia<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://www.cebix.net/pipermail/ginac-list/attachments/20110328/e099292a/attachment-0001.html" target="_blank">http://www.cebix.net/pipermail/ginac-list/attachments/20110328/e099292a/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Mon, 28 Mar 2011 16:46:48 +0300<br>
From: Alexei Sheplyakov <<a href="mailto:alexei.sheplyakov@gmail.com">alexei.sheplyakov@gmail.com</a>><br>
To: GiNaC discussion list <<a href="mailto:ginac-list@ginac.de">ginac-list@ginac.de</a>><br>
Subject: Re: [GiNaC-list] assignment<br>
Message-ID:<br>
<<a href="mailto:AANLkTimV2YQ0Ut2OEhUDbuq%2BXh3Qzj96Z28A61ZsXKO8@mail.gmail.com">AANLkTimV2YQ0Ut2OEhUDbuq+Xh3Qzj96Z28A61ZsXKO8@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Hello,<br>
<br>
> rinterval inter(a,b,(numeric)0.00001);<br>
^^^^^^^^^^^^^^^^^^^<br>
<br>
Casting double to GiNaC::numeric is absolutely wrong. For starters,<br>
sizeof(numeric) != sizeof(double), numeric is reference counted, and<br>
double is not, and so on. Just don't do this. Use the normal constructor<br>
instead, that is<br>
<br>
rinterval inter(a, b, numeric(0.00001));<br>
<br>
Best regards,<br>
Alexei<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
GiNaC-list mailing list<br>
<a href="mailto:GiNaC-list@ginac.de">GiNaC-list@ginac.de</a><br>
<a href="https://www.cebix.net/mailman/listinfo/ginac-list" target="_blank">https://www.cebix.net/mailman/listinfo/ginac-list</a><br>
<br>
<br>
End of GiNaC-list Digest, Vol 69, Issue 3<br>
*****************************************<br>
</blockquote></div><br>