Question about mpf_add

Bruce M. Axtens bruce.axtens at gmail.com
Sat Oct 4 20:29:13 CEST 2008


G'day everyone

Context:
    gmp-static-vc-4.1.2
    Microsoft Visual C++ 6.0
    Windows XP Professional SP3

In the code below I use mpf_add in what I assume to be the canonical 
way. What I don't understand at this point is why 2.2 + 3.2 = 
5.39999999999999999999999999999999999999. I would have thought that
gmp was smart enough to give 5.4.

What else should I be seeing in the manual that I'm not?

Kind regards,

Bruce M. Axtens
Software Engineer
The Protium Project

---

#define F(x) mpf_t x; mpf_init( x );

BSTR __stdcall FBIGSUM(BSTR p1, BSTR p2 ) {
    USES_CONVERSION;
   
    F(n1);
    F(n2);
    F(res);
   
    LPSTR sNum1 = W2A( p1 );
    LPSTR sNum2 = W2A( p2 );

    mpf_set_str( n1, sNum1, 10 );
    mpf_set_str( n2, sNum2, 10 );

    mpf_add( res, n1, n2 );

    char * buff =  (char *) _alloca( 1024 );
    char expBuffer[ 20 ];
    mp_exp_t exp;

    mpf_get_str(buff, &exp, 10, 0, res);

    char * temp = ltoa( (long) exp, expBuffer, 10 );
    if (exp >= 0) {
        strcat(buff, "+" );
    }
    strcat(buff, expBuffer );

    BSTR bResult = _com_util::ConvertStringToBSTR( buff );
    return bResult;
}



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gmplib.org/list-archives/gmp-discuss/attachments/20081005/5e3da64a/attachment.html 


More information about the gmp-discuss mailing list