[GiNaC-list] assignment

Nisoli Isaia nisoli at mail.dm.unipi.it
Wed Mar 30 12:13:46 CEST 2011


Hello,
it seems the error was given by the explicit destructor I wrote for
the class rinterval,
which I didn't attach in my first mail.

Indeed, erasing from the code the destructor

rinterval::~rinterval()
{
 min.~numeric();
 max.~numeric();
 error.~numeric();
}

the code works fine.

Thank you,
best regards
Isaia

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


More information about the GiNaC-list mailing list