Hmmm.... I underestimated. pow(99999.99999,99999.99999) = 9.998748785736894607828527462269893046126336085 91664915498635306081273911645075964079222720857427 35641018572673827935330501923067157794798212338823 24997145234949798725508071849154834025252682619864 09675931105114160107573542813573334036043627693673 32584230414090115274301822704676399594689777183090 95124350838052746795283582659784697437868624515447 84308955024802754764364277858847454870139679632204 93566098207186651878539285222697852739872657689082 77740528466769263852694444704577829403518386946691 11157539964528436618742040945886361696712501785143 49612003446329175703756667138162553151705912580792 12331560317684418171064195077598932031644579554853 98595138860229023469055949001949521877405516916475 97554564462253024119778312344592336542732038212175 43130812948451126588746192211036266786198594583755 89036373827433475892132965189682874790600247279436 07120265912512012429492123644988164587146533255393 93335345599658088256314460922495519381049143246081 37075434256493449284197921246089978660147299071527 8174795070535064342859550611e499999 So the precision calculation would be much more complicated. > -----Original Message----- > From: Dann Corbit > Sent: Thursday, May 19, 2005 2:20 PM > To: 'Martijn van Oosterhout' > Cc: Alvaro Herrera; John Burger; pgsql-general@xxxxxxxxxxxxxx > Subject: RE: numeric precision when raising one numeric to > another. > > If you want to create a pow() function for numeric using existing numeric > functions, it [the new function] should be aware of the precision of the > inputs, and the precision of the output should be their product. > > So, if you do pow(numeric(10,5), numeric(10,5)) then the result column > should be numeric(100,25) if you want to retain full precision. > > > -----Original Message----- > > From: Martijn van Oosterhout [mailto:kleptog@xxxxxxxxx] > > Sent: Thursday, May 19, 2005 2:02 PM > > To: Dann Corbit > > Cc: Alvaro Herrera; John Burger; pgsql-general@xxxxxxxxxxxxxx > > Subject: Re: numeric precision when raising one numeric to > > another. > > > > On Thu, May 19, 2005 at 10:41:51AM -0700, Dann Corbit wrote: > > > We use Moshier's excellent qfloat numbers. > > > http://www.moshier.net/qlib.zip > > > Documentation: > > > http://www.moshier.net/qlibdoc.html > > > > > > So, if you do the following query using CONNX: > > > select convert(pow(9.5,5.9), varchar) > > > You will get: > > > > 586906.97548405202106027547827738573075504470845684721318303336760202394 > > > 5916438064873363100477233500417619 > > > > But it's not accurate enough with the default settings. For example > > 2^100: > > > > # select exp( ln(2::numeric) * 100 ); > > exp > > -------------------------------------------------- > > 1267650600228229400579922894637.9015824515440063 > > (1 row) > > > > The answer should be: > > 1267650600228229401496703205376 > > > > So it's wrong from the 14th digit onwards. If that's the case you may > > as well stick to using floating point. It does however appear you can > > influence the precision, See: > > > > # select exp( ln(2::numeric(50,30)) * 100 ); > > exp > > ---------------------------------------------------------------- > > 1267650600228229401496703205375.991370405139384131115870698781 > > (1 row) > > > > Using numeric(50,25) gets you only 28 correct digits. So, if you know > > how big your result is going to be you can adjust the types to match > > and get whatever precision you want. Given that you can estimate the > > number of digits easily enough (it's linear with the value before the > > exp()) maybe you can get it to automatically choose the right > > precision? > > -- > > Martijn van Oosterhout <kleptog@xxxxxxxxx> http://svana.org/kleptog/ > > > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is > a > > > tool for doing 5% of the work and then sitting around waiting for > > someone > > > else to do the other 95% so you can sue them. ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@xxxxxxxxxxxxxx)