Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

(expt 9.5 400) and (expt 9.4721 400)

9 views
Skip to first unread message

Hen Hanna

unread,
Jun 18, 2022, 11:52:41 AM6/18/22
to

here using Gauche implementation of Scheme (Lisp)
_________________________

gosh> (expt 2 10)
1024

gosh> (expt 95 400)
122868941115179737710771763422406480301757540139859458808109124467070985446636432601124226198138372384827136835747639824957217872566284270584970573806709719276387720717338491937768940125341858818232921546470367105745159050900738732857641177973934199359975283304040662214527892754581251472028550573377465974149524776907053647487276218630915991403393175918807721542352052061931828388937244412868178358157101355186823815679746336760233122803664930597166935876581382936048661922495177503814998271180126016615741029048421718399550885061036453398850989384221230496760667725343755621356110646439201800024101683783925799569271375473948166129904365762856539506504738909912793972528107696543949955683957699890196644331714953888959611025828637994242150674323852711788962466243901872076094150543212890625

gosh> (expt 9.5 300) --> 2.075303347768084e293

gosh> (expt 9.5 400) --> +inf.0


SO... With ( 9.5 ^ 400) i can get the exact value, but
what i want to do is to get an approx. value of

( A ^ 400 ) where

A is 9.47213595499958
or
A is (+ 5 (* 2 (sqrt 5)))



is there a way to do this?

Hen Hanna

unread,
Jun 18, 2022, 12:03:36 PM6/18/22
to
(expt 947213595499958 400) gives me an approx value,
but i guess i'm asking for 1000 or million times as many digits.

so it seems far beyond what my cheap PC can do.

James Cloos

unread,
Jun 18, 2022, 6:28:05 PM6/18/22
to
i’m not up on scheme’s details, but with common lisp those floats
default to single-float, which is usually implemente these days with
a 32-bit ieee float.

using l as the delimiter between the significand and the exponent
will generate a long-float, with more resolution.

on an arm64 sbc, and using ecl, i get:

> (expt (+ 5l0 (* 2l0 (sqrt 5l0))) 400)

3.7946276521800698015l390

for more digits one’d need to use multi-precision floats.

i have no idea whether any scheme implementations include any mp float
support as is, but they should let you use an extertnal library such as
mpfr for that.

your pc is certainly good enough; you just need the right software.

(they do not make any these dayswhich are not good enough; not even at
the sub-$30 price point.)

In maxima:

(%i3) (2b0*sqrt(5b0)+5b0)^400b0,fpprec:999;
(%o3) 3.7946276521800697305666550087536192992115769295190551691665658622025488\
195527774282584577158133760363054128087496967891514764773751875434079622491760\
760697880911146535967511959796900645429566665476227663091405183155412705120528\
107603481804507230138239252996700097573900617537077884807268892365403939464952\
884993314087737184104485796978046070820564123621254637441779777873307466506958\
007812499999999999999999999999999999999999999999999999999999999999999999999999\
999999999999999999999999999999999999999989794540413933744145337696735909814614\
790479700848425376607266434711262904353407710432649693087316786760610501184349\
347109985584947803067028202580520987298601120677255115594828007214424540451843\
222471830925057425575004834959741740703164533089752802924419634880343840285041\
613337373169098123721455216932346242326642176737006286464924950409814547065789\
596130406436031620557787620213303967542302476673429612247644081703293433164688\
6414110731231241578737816677781912052635857679622387021664384404205661b390

(the b means bfloat, fpprec is the bfloat precision.)

-JimC
--
James Cloos <cl...@jhcloos.com> OpenPGP: 0x997A9F17ED7DAEA6

Paul Rubin

unread,
Jun 18, 2022, 6:32:34 PM6/18/22
to
Hen Hanna <henh...@gmail.com> writes:
> is there a way to do this?

The issue is that 9.5**400 is around 1e390 which is larger than the ieee
fp64 maximum value of around 1e308. While there is an extended format
with a wider range, it is probably simplest to use logarithms:

(define (log10 x) (/ (log x) (log 10.0)))

(define x0 (+ 5 (* 2 (sqrt 5)))) ; 9.472...

(define y0 (* 400.0 (log10 x0))) ; log10(x0**400)

(let* ((y1 (floor y0))
(y2 (- y0 y1)))
(display `(,(expt 10 y2) "* 10**" ,y1)))
(newline)

prints (3.794627652179525 * 10** 390.0) when I try it in Guile.
0 new messages