English
Source / code snippets

larger Faktorielle to charge

 

p.specht

here a slower Variante, with the but the Nummernbasis changed go could (this is in Cryptosystemen sometimes demand):
Window Title "Größere Faktorielle berechnen"
'(CL) CopyLeft 2014-09 by P.woodpecker, Wien; No however geartete Gewähr!
'Orig.-Source from https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic
Window 0,0-%maxx,%maxy
font 2
var Limit& = 10000' Sufficient digits.
var Base&  = 10' The base of the simulated arithmetic.
var FactorialLimit& = 365' Default of Target number to solve, 365!
Declare digit&[Limit&]' 1..Limit&: The big number.
declare carry&,d&' Assistants during multiplication.
declare last&,i&,n&' Indices to the big number's digits.
declare Text$,c$' Scratchpad for output and for input
declare tdigit$[] : tdigit$[]=explode("0 1 2 3 4 5 6 7 8 9"," ")
BEGIN:
Print "\n number, from the The Faktorielle errechnet go should: ? ";:Input c$
case val(c$)>0:FactorialLimit&=val(c$)
digit&[]=0' Clear the whole aray.
digit&[1]=1' The big number starts with 1,
last&=1' Its highest-order digit is number 1.

whileloop FactorialLimit&

    n&=&Loop' Step through producing 1!, 2!, 3!, 4!, etc.
    carry&=0' Start a multiply by n.

    whileloop last&:i&=&Loop' Step along every digit.

        d&=digit&[i&]*n&+carry&' The classic multiply.
        digit&[i&]=(d& mod Base&)' The low-order digit of the result.
        carry&=d& \ Base&' The carry to the next digit.

    endwhile

    while carry& > 0' net curtain the carry in the big number.

        if last&>=Limit&

            print "Overflow!";' If possible!
            beep: waitinput :end

        endif

        last&=last& + 1' One more digit.
        digit&[last&]=carry& mod Base&' Placed.
        carry&=carry& \ Base&' The carry reduced.

    endwhile' With n > Base, maybe > 1 digit extra.

    case rnd()<0.1:print "*";
    ' Print n&;"! = ";text$+" ("+st$(len(Text$)-1)+" to put)"  ' Print the result!

endwhile' On to the next factorial up.

text$=" "' Now prepare the output.

whileloop last&:i&=&Loop' Translate from binary to Text.

    Text$=tdigit$[digit&[i&]]+text $' Reverse the order.

endwhile' Arabic numerals put the low order last.

cls
Print "\n "+st$(n&)+" ! = ";text$+" ("+st$(len(text $))+" to put)"
clearclip:putclip st$(n&)+" ! = "+text $+"\n"
print "\n Last result in clipboard! "
sound 300,300 : waitinput
END
 
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/15/21  
 




p.specht

Faktorielle To Facf(100000)
========================
XProfan with Floats can the really only To 170. The Overflow-Error becomes here but abgefangen, the Result by Minuszeichen marked and via Zehnerlogarithmus errechnet. with the spending becomes the less then properly interprets, The Stellenzahl the Mantisse is then but only on about 12 signifikante Kommastellen validly.
Proc Facf :parameters N&:casenot N&:return 1.0

    if N&>100000:print " *** FAC() TOO BIG! *** ";:beep:return -100000:endif

        if N&<171:var p!=1:whileloop N&:p!=p!*&Loop:endwhile:return p!

            else :var s!=0:whileloop N&:s!=s!-lg(&Loop):endwhile:return s!:endif

        ENDPROC

        Declare n!,F!

        Repeat

            print " n = ";:input n!:F!=Facf(n!)
            print " Facf(";int(n!);") = ";

            if F!>=0:print stature$(" %g",F!)

                else :set("decimals",17)
                print st$( round(10^(int(F!)-F!),13))+"e+"+st$(int(-F!) )

            endif

        Until 0

 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/27/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.721 Views

Untitledvor 0 min.
Erhard Wirth06/14/24
p.specht11/21/21
R.Schneider11/20/21
Uwe Lang11/20/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (2x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie