You are on page 1of 27

SpeedCrunchversion0.

10math
CopyrightWolfLammen2008
ReleasedunderGNUFreeDocumentLicence1.2
Visithttp://www.gnu.org/licenses/fdl.htmlfordetails.

PhilosophyofInput
WhenyoufirstlaunchSpeedCrunchyoumightbetemptedtouseitlikeanordinarypocketcalculator,
thatispunchwithyourmouseonthekeypadtoproduceresults.
ButSpeedCrunchhasbeendevelopedwithfastkeyboardusageinmind.Ofcourse,atyouroption,
youmaysticktomouseandgraphicalelementsforinput,buttherecommendedwayistypinginyour
expressions.
So,rightafteryoulaunchedofSpeedCrunch,aninputfieldisreadilyawaitingyourkeystrokes.The
textyouenterthereisalwaysanarithmeticformuladescribingyourdesiredcalculation,assimpleas
1.234+2.987
orascomplexas
sqrt(2*pi)*exp(lnx*x0.5).
Expressionsliketheselookverymuchliketheformulasinmathematicstextbooks,andthisformof
inputisknownasalgebraicnotation.
Onceyouhaveenteredaformula,youpresstheENTERkeyforevaluation,andtheresultwillbe
displayed,alongwithyourformula,inthewindowabovetheinputfield,calledresultwindow.
Theresultwindowdoesnotonlyshowyourlastoperation,itsavesahistoryofwhatyouentered
before.Thisgivesyouanoverviewoverallyourcalculations,andyoumayrecallanyofyourformer
inputby,well,clickingonthecorrespondingpositionintheresultwindow,or,faster,byusingtheUP
andDOWNARROWkeys.
Bynow,youshouldalreadybeabletouseSpeedCruncheffectivelyinanintuitiveway.Maybe,you
wanttoentersomeexpressionsofyourownnow,andlearnhowSpeedCrunchreactsonyourinput.

Algebraicnotation
Whatnowfollows,isashortintroductiontoalgebraicnotation.Thisisnotaboutteachingyoumath
again,wejustwanttointroducesometermsforlaterreference,andgiveyouanoverviewoverthe
inputsyntax.
Asimpleexpressionlike
1+2
hasthreeelements:Twooperands,namely1and2,andabinaryoperator+.Binary,becausethe
operatortakestwooperands,incontrasttounaryoperators,thattakeoneoperandonly.Onesuch
operatoristheminussign,ornegation:
pi.
Becauseitprependsitsoperand,itiscalledaprefixoperator.Unaryoperatorsfollowingtheiroperand

areconsequentlycalledpostfixoperators,liketheexclamationmarkin
8!
Whenthereismorethanoneoperatorpresentinaformula,conflictsituationsarise.Howshalla
formulalike
1+2*3
beexecuted?Additionfirst,ormultiplication?
Maybeyourememberfromschool,thattherecomesaprecedenceorderwithoperators.Thatway,
therulesofalgebraicformulasclarifysomeoftheseconflicts,byassigningahigherprecedencetothe
multiplicationthantotheaddition,forexample.
SpeedCrunchknowsthisprecedenceorderandappliesittoyourinput.Sotheresultoftheabove
formulais7,not9,aswouldbewithstrictlefttorightevaluation.
Anotherwaytoestablishanevaluationorderistheuseofparenthesis.Incaseofdoubtaboutthe
precedenceorder,theuseofparenthesisisrecommended.
Sotheformula1+2*3mayberestatedmoreclearlyas
1+(2*3).
Whenoperatorsaredifferent,precedencerulescantellhowtoexecuteaformula.Buttheyfailto
resolveconflictswithseriesofoperatorsofthesamekind,orprecedence,asin
1251377.
Soasecondsetofrules,calledtheassociativityofanoperator,determineswhattoevaluatefirstthen.
Theevaluationorderisalmostalwaysfromlefttoright.Sotheaboveexampleisequalto
(12513)77.
Wehavejustonebigexception,thepoweroperator^(or**):
2^3^4
means2^(3^4).Itsassociativityisrighttoleft.
SpeedCrunchimplementsasetofthemostcommonmathematicalfunctionslikelog,sinandsoon.
Functionstakeparameters,sometimesjustasingleone,oruptoarbitrarilymany.Youstarta
functioncallbytypingthefunctionname,followedbytheparameter(s),theparameterlist,enclosed
inparenthesis:
ln(2)/ln(10).
Ifyousubmitmorethanoneparameter,separatethembyasemicolon:
nCr(17;3).
Afunctionlikeaveragetakesarbitrarilymanyparameters:
average(1;2;3;4;5;6)
Eachparameterinturncanbeanexpression:
geomean(sqrt(3);tan4;7+5)

Asanabbreviation,ifafunctiontakesjustoneparameter,yousometimesmayomittheparenthesis.
Forinstance,wemayrewriteoneoftheexamplesaboveas
ln2/ln10.
Butifyouwanttoevaluate
ln(2/3),
youneedthebraces.Functionseatupasmuchofyourfollowinginputasisnecessarytocompletethe
neededparameter,butnotmore.So,withoutbraces,theabovestatementisinterpretedas
(ln2)/3,
becausethenumber2isalreadyrecognizedasavalidparameter.Again,ifyouareindoubtofhow
SpeedCrunchinterpretsyourinput,useparenthesis.
Hereisanexampleofamorecomplexparameterinvolvingoperatorsandfunctions:
lnlnlnln3,
whichisequivalenttoln(ln(ln(ln3))).
SpeedCrunchofferstheusageofvariables.Youassignavaluetoavariablebyusingthe'='character:
x=sqrt2.
Ifxexistedbefore,itsformervalueisnowoverwrittenbythesquarerootof2.Iftherewasnosuch
variable,itiscreatedandassignedthegivenvalue.
Onceyouhavedefinedavariable,youmayuseitinanylocation,whereanumberconstantisvalid.
So,withtheabovedefinitionofx,
x*x
shouldyieldtheresult2.
Itisallowedtousethesamevariableontheleftandrighthandsideof'=':
x=2*x
doublesthecontentsofx.Theexpressiontotherightofthe'='isevaluatedfirst,usingtheoldvalueof
x,beforetheassignmenttakesplaceandoverwritesthevalueofx.

Literalnumberconstants
Themostbasicsortofinputtoacalculatoristhatofastatinganumbervalue.SpeedCrunchfollows
theusualinputruleswellknownfromotherprograms,soyourintuitionwillbealmostalwaysright.
However,thereareafewcornercases,thatshouldbementionedhere.Westartwiththedecimaldot,
acharacter,thatisnotfixedinSpeedCrunch.Therearecountries,thatuseacommainsteadofadot,
soyoumaycustomizeSpeedCrunchtoyourparticularneeds.TheSettingsmenuprovidesadialogue
window,whereyoucanpickyourfavouritecharacter.Throughoutthismanual,wewillassumeyou
choseadot.
Aprecedingminusisneverpartofanumberliteral;itistreatedasaunaryoperatorappliedto
followingunsignedliteralconstant.Thisissometimesvisible,forexamplein0.5!,whichisexecuted
as(0.5)!.And,unlikecommonusage,unaryoperatorstakeprecedenceoverthepower(^or**)
operator.Thisislikelytochangeinafuturerelease.

fixpointformat

Integersaregivenasasequenceofdigits,
1234
forexample.
Thefirstdigitneednotbenonzero,asin
0023.
SpeedCrunchiscapableofholdingintegersupto78digits,withoutalossofadigit.Ifyourinputhas
morethan78significantdigits,thisissilentlyconvertedintoanapproximatevaluealwaysoftheright
scale,butwithatruncateddigitsequence.
Realnumbersarecharacterizedbyanonzerofractionalpart.
12.345
isanexampleofsuchanumber.Youmayappendasmanytrailingzerostoafractionasyoulike,or
putleadingzerostothefrontoftheintegralpart,asin
0012.3450000
Iftheintegralpartofanumberiszero,youmayomitthezeroaltogetherandbeginyournumberwith
thedecimaldot:
.005
isthesameas0.005.
Realnumberscanholdupto78significantdigits;ifyoustatemore,anapproximatevalueoftheright
scale,butwithatruncateddigitsequenceisstored.Apartfromthistruncation,yourliteralconstants
entercalculationswithoutconversionorroundingerrors,becauseSpeedCrunchusesinternallya
decimalencoding.
scientificformat

Themostgeneraltypeofanumberliteralisgivenbythescientificformat.Here,thescale(or
magnitude)ofavalueisseparatedfromitssignanddigitsequence,thesignificand.Thisformat
allowssimpleinputofhugeortinynumbers,whosefirstsignificantdigitlieswaytoofarawayfrom
thedecimaldotforcommonnumberrepresentation.Youwillfindthisformatonscientificpocket
calculatorsaswell,somaybe,youarealreadyfamiliarwiththisformat.
Thescaleofanumber(sometimescalleditsexponent)beginswiththescalecharacter'e'or'E'
followedbyasignedinteger.So'e+10','e4','E0'areallvalidscaleexpressions.Ifthesignis'+',you
maysimplyomitit:'e0','E10'.
Themeaningofascaleexpressionis'*10exp',whereexpisthesignedintegervaluefollowingthe
scalecharacter.Asyoumightseefromthis,astandalonescaleexpressionismeaningless,becauseyou
needanotherfactortomakeupacompleteproduct.Thisotherfactoriscalledthesignificand(or
mantissa),anditalwaysprecedesthescale.Avalidsignificandisanyordinary(nonscaledfixpoint)
realnumberorinteger,givenasanumberliteralaccordingtotheprevioussection.Here'salistof
validnumberliteralsinscientificformat,meaning1.2*103,7*104,0.3*1012,14.8*109,resp.
1.2e+3

7e4
.3e12
14.8e9
Usually,significandsarenormalized,i.e.theyfulfil1<=significand<10,butthelistedexamples
show,thatthisisnotrequiredbySpeedCrunch.
Ifthescalevalueiszero,thescaleiseffectivelyredundant,because'*100'reducesto'*1'.Soadding
ascale'e0','E0'toanumberdoesnotmakeanydifference.
0canbecombinedwithanyscalevaluewithoutaffectingtheresult,so0e0,0e100000,0e10000will
allyield0.
Bygivinghugescalevalues,youcanproducenumbersneartheoverfloworunderflowlimitof
SpeedCrunch(1e+/536870912).OverfloworUnderflowisnotdeterminedbythescalevaluealone;it
istheproductofscaleandsignificandthatdeterminestheresult.Soin
0.000001e536870916
thescalepartoverflows;butitisvalidinput,though,becausethefinalresult,1e536870910,isbelow
thelimit.
Youcanspecifyjustasinglescaleinaliteralnumberconstant.1e10e5isnotgrammatical.
inputtobases2,8and16

ThehandlingofbinaryencodednumbersisstillnotwellintegratedintoSpeedCrunch;thereiswork
inprogresstorelievethissituation.ButthenecessarychangestothecodebaseofSpeedCrunch
provedtobetoomassivetobereadyforversion0.10.
Forthetimebeingsomepreliminarysupportisprovided.
Youcanenterunsignedintegersupto22561directlybyaddingaradixprefixtothefrontofthedigit
sequence.Validprefixesare

'0x','0X','0h','0H','#'forhexagesimaldigitsequences;

'0o','0O'foroctaldigitsequences.Note:itdoesnotsufficetostartadigitsequencewith0to
markitasoctal;

'0b','0B'forbinarydigitsequences;

'0d','0D'fordecimalsequences.Thisisredundant,SpeedCrunchwillassumethisbydefault.

Ifyouenterahexagesimaldigitsequence,thedigits'10'to'15'are,asusual,representedbytheletters
'A'to'F'.Youmayusetheirlowercaseformaswell.
Sovalidinputis:
0xFA67
0b1001000100100111
0o7212627
#8a
Asmentioned,allthesevaluesareunsignedintegers.Youcannotspecify1by0xFFFFFFFF,for

instance.Youcancreatenegativenumbersby

useofnegation:thefollowingyields10
0xA

useofthefunctionunmasktoconvertanunsignedintegertoitssignedcounterpart:the
followingevaluatesto1
unmask(0xFFFF;16)

SpeedCrunchcanswitchoutputmodetootherradicesthan10aswell,butthisaffectsoutputonly;for
inputyoustillneedtheradixprefixes.Soevenin'hex'outputmode,youmustnotforgetthe'0x'(or#,
or..)tagonhexagesimalinput.
Youmayfreelymixoperandstodifferentbasesinacalculation:
17*0xFA0b10010001
oreven
sqrt(0xff),
althoughtherealvaluedresultisfullyshownindecimaloutputmodeonly.

Mathengine
Allcalculationsaredoneinaprogrammodulecalledthe'mathengine'.Weprovideyouwithsome
internalsofthismodulehere,shouldthisknowledgebenecessarytounderstandSpeedCrunch's
behaviourincornercases.Usually,youcansafelyskipthisparagraph.
SpeedCrunchstoresandevaluatesallvaluesinanormalizedscientificformat.Thesignificandkeeps
thesignand78decimaldigitsplusthreeguarddigits.78digitshavebeenchosentoallowkeepinga
256bitunsignedintegerwithoutlossofdigits.
Thethreeguarddigitsareprivatetotheengine;youmustnotrelyontheirvalues.Theyaremeantto
collectallroundofferrors,andpreventthemfrompollutingthefirst78digits.Theirexistenceis
occasionallyvisible,forexample,whenyousubtracttwoalmostequalnumbers.Theguarddigits
neverleavetheengine;onexporttheroundedresulttoatmost78digitsarewritten.
Thesignificandofaninternalvalueiseither0,oritsabsolutevalueisfrom1<=significand<10.So
thescaledescribesapowerof10andisaplainsignedintegerof30bitswidth,soitcanassumevalues
between536870912and536870911.Thesearetheboundsofthevaliddatarangeoftheengine.Any
biggerorsmallerscaleproducesanoverfloworunderflowerror.Anintermediateresultissubjectto
thisboundcheckingaswell,soyoumayreceiveanoverfloworunderflowerror,evenifthefinal
resultwouldberepresentableintheengine'svaluerange.
Aspecialencodingisreservedforasocalled'NotaNumber'(orshort:NaN).Thisisthevalue
returnedonerror.TheenginereturnsaNaNalongwithanerrorcodedescribingthekindoferrorin
moredetail,butthecurrentSpeedCrunchimplementationdiscardstheerrorcodeandsimplyreports
NaN.
Theenginerecognizesthefollowingtypesoferror:

NaNoperand:YoutriedtoperformanoperationonaNaN.ThisNaNismostprobablythe
resultofaformerfailedoperationthatnowpropagatesthroughtherestofyourcomputation,
butitmayindicateanotinitializedvalueaswell.

Overflow,Underflow:A(finalorintermediate)resultviolatestheboundsofvalidnumbers

TooExpensive:Someoperationscanbepotentiallyveryexpensive,likethemodulooperation.
InordertopreventSpeedCrunchfromfreezing,thiserrorisissued,whentheenginedetectsa
situationthatwouldrequiretoomuchtime.

Unstablealgorithm:Ifyoutrytoevaluateafunctionveryclosetoapole,theresultmightbe
dependentontheguarddigitsonly.Insteadofreturninganalmostrandomresult,theengine
issuesthiserror.Thesameholds,ifyoutrytoevaluateaperiodicfunctioninanumberrange
whereitsperiodicityisnotrecognizedanymore,becauseanychangeofthe78thdigitofthe
argumentcoversalreadymorethanonecycleofthefunction.

OutofDomain:somefunctionslikelnorsqrtcannotbeappliedtoallrealnumbers.Ifyou
passaninvalidparametertosuchafunction,yougetthiserror.

DividebyZero:Youtriedtodividebyzero,evaluatedafunctionatapole,orused0asa
modulo.

Theinternaldecimalencodedscientificformatisnotappropriateforlogicoperations.Youneed
binaryencodedoperandsforthis.Aconversionunitinthemathenginetakescareofthat.The
conversionislimitedtointegersrangingfrom2255to+22561.Negativenumbersareconvertedtoa
256bittwo'scomplementrepresentation.Positivenumbersyieldabitpatternrepresentingtheirvalue
inbinaryencoding.Notethattheconversionissometimesambiguous:2255and+2255havethesame
bitpattern.Althoughlogicoperationstakeintegers>=2255asoperands,theirresultarealwayssigned
integersfrom2255to+22551.

Unaryoperators
Herecomesalistofallunaryoperators:
unaryprefixoperator+

iseffectivelyanooperation,andthereforealwaysredundant.
+++2.77
isthesameas2.77.
The+operatorishigherinprecedencethananybinaryoperator,butlowerthanpostfixoperators.
A+precedingaliteralnumberconstantisnotrecognizedaspartofthatconstant,buttreatedasan
unaryoperatorinstead(albeitthisdifferencedoesnotmatter).
Asingle+precedingascaleintegerisaredundantpartofthatconstant:
1e+33
isOK,but1e++33isnot,becauseinsidealiteralconstantnocomputationtakesplace,andthis
operatorisnotappliedtoremoveanyofthe+.
Thisoperatorisapplicabletoallrealnumbers.
unaryprefixoperator

negatesanumber.
2.77

isthesameas2.77.
Theoperatorishigherinprecedencethananybinaryoperator,butlowerthanpostfixoperators.
Aprecedingaliteralnumberconstantisnotrecognizedaspartofthatconstant,buttreatedasan
unaryoperatorinstead.Thisisvisibleinexpressionslike0.5!,whichisevaluatedas(0.5!),because
thepostfixoperator!takesprecedenceovertheunaryoperator.
Asingleprecedingascaleintegerispartofthatconstant:
1e33
isOK,but1e+33isnot,becauseinsidealiteralconstantnocomputationtakesplace,andthis
operatorisnotappliedtofindthesignofthescale.
Thisoperatorisapplicabletoallrealnumbers.
unarypostfixoperator!

findsthefactorialoftheprecedingvalue:
10!
returns10*9*8*7*6*5*4*3*2*1==3628800.
Maybethiscomesasasurprisetomanyusers,butmathematicianshaveinterpolatedthefactorialsina
decentway.So
(0.5)!
turnsouttobethesquarerootofpi.
SpeedCrunchknowsofthisextensionandreturnsfactorialsevenofnonintegers.
Thefactorialpostfixoperatorhashigherprecedencethantheunaryoperators+or,so
0.5!
isevaluatedto(0.5!)==sqrt(pi)/2.
Thefactorialofnegativeintegerscannotbecomputed.
Thefactorialisgrowingtremendouslywithitsargument,andoverflowsnear72306960.008...Onthe
negativeaxisitunderflowsnear72306961.008...Ofcourse,thepolesatnegativeintegersreturn
errors,too.

Binaryoperators
Here'salistofallbinaryoperators.
binaryoperator+

performsanordinaryaddition.
12.73+465.44
Theprecedenceofthisoperationislowest.
Theadditionisaninherentlyunstableoperation,whenyouaddtwooperandsofalmostthesame
value,butoppositesigns.Thismeans,theresultdependsonlesssignificantdigitsofbothoperands,

andistypicallynotvalidtoall78digits.
WhenaddingvaluesneartheoverfloworunderflowlimitofSpeedCrunch,thisoperationmay
overfloworunderflow.
binaryoperator

performsanordinarysubtraction.
12.73465.44
Theprecedenceofthisoperationislowest.
Thesubtractionisaninherentlyunstableoperation,whenyousubtracttwooperandsofalmostthe
samevalue.Thismeans,theresultdependsonlesssignificantdigitsofbothoperands,andistypically
notvalidtoall78digits.
WhensubtractingvaluesneartheoverfloworunderflowlimitofSpeedCrunch,thisoperationmay
overfloworunderflow.
binaryoperator*

performsanordinarymultiplication.
12.73*465.44
Theprecedenceofthisoperationishigherthan+or,butlowerthanaunary.
Forveryhugeorverytinyoperands,thisoperationmayoverfloworunderflow.
binaryoperator/

performsanordinarydivision.
12.73/465.44
Theprecedenceofthisoperationishigherthan+or,butlowerthanaunary.
Forveryhugeorverytinyoperands,thisoperationmayoverfloworunderflow.
Youcannotdividebyzero.
binaryoperator^
binaryoperator**

Bothoperatorsaresynonymsforthepoweroperator.
12.4^3
raises12.4tothe3rdpower(==12.4*12.4*12.4==1906.624).
Theprecedenceofthisoperatorishigherthanunary+or,butlowerthanfunctioncalls.
Usinglogarithms,theraisingofpositivenumberstoanyrealvaluedpoweriswelldefined:
12.4^3.7
returnsaresultnear0.00009.

Youcandrawthenthrootofanumberbyraisingittothe(1/n)thpower:
12.4**(1/5)
drawsthe5throotof12.4(==1.654..).
Apowerofzeroiszero,iftheexponentispositive,otherwiseitisanerror.
Iftheexponenthasnofractionalpart(isaninteger),SpeedCrunchallowsnegativenumbersasbases:
(2.6)^5
isOK.
However,ingeneral,raisinganegativenumbertoanarbitrarynonintegerexponentisnotpossiblefor
SpeedCrunch,because

therealwaysexistatleasttwo,usuallyinfinitemanyresults;

theseresultsare,inrarecaseswithjustoneexception,truecomplexvalues,especiallythe
principalvalueisalwayscomplex.

Therarecasesarewhentheexponentisrational,anditsdenominatorisodd.
Forexample,the3rdroot(or(1/3)rdpower)of(1)hasthreesolutionsinthecomplexplane,namely
(sqrt(3)/2+1/2*i),(1)and(sqrt(3)/21/2*i).Ofthese,thefirstisdenotedbymathematiciansasthe
principalvalue(andnot(1),thatissonicelyrealvalued).
Withoutdelvingtoodeepintotheoryhere,onecansee,thatitisimpossibletospotthefew
exceptions,whereasinglenegativerealvaluedresult(amongmanyothers)exists.Sincetheexponent
ispassedapproximatelyonly(1/3hasbeenconvertedto0.3333...before)tothepowerroutine,it
cannotsafelybeidentifiedasofrationaloriginanymore.
SoSpeedCrunchalwaysreturnsanerror,whenitisrequestedtoraiseanegativenumbertoanon
integerpower.
Weexplainedthereasonshereinsomedetail,becausepeoplearesometimesconfusedwhenthey
learnthatcbrt(2)yieldsaresult,but(2)^(1/3)doesnot.
Especiallywhenexponentsareverylarge,thepoweroperationoverflowsorunderflowseasily.

StatisticalFunctions
probabilitydistributions

SpeedCrunchsupportscommonprobabilitydistributions.Sincemanydistributionsdefinethesame
setoffunctionsandcharacteristicvalues,wewilldescribetheircommonmeaninghere.
Asingleprobabilistictestortrial(likethrowingadice)hasarandomoutcome.Thereissome
freedomabouthowwedefineoutcomes.Wecanbeveryspecific,e.g.enumeratingallpossibleresults
ofadicethrow,orwecansubsumeseveralofthem,e.g.seewhetherasixisshown,ornot.Such
possiblysubsumedoutcomesarecalledevents.Inaddition,wewillassumehere,thatyoucan
describeeventssufficientlybyasinglenumber.Ifthepossibleresultsreducetoasetoftwomutually
exclusiveevents,wetalkaboutayes/notest.
All(numerical)outcomesareeither

fromafixedfinitesetofpossibleoutcomes(likethefacesofthedice);

fromacontinuousrange(likethelengthofanobject).

Ifthesetofoutcomesisfinite,youcanassigneachoftheoutcomesavalue,itsprobabilityp,that
describeshowlikelythisoutcomeis.Itisalwaysarealvaluebetween0and1,boundsinclusive
(Multipliedby100,thisvaluegivesthechanceofthespecificoutcomeinpercent).E.g.,ifyouuse
unbiaseddices,theprobabilityoftheoutcomesixisexactly1/6,asitisforallotherpossibleresults.
Thefunctionmappingthepossible(andmutuallyexclusive)eventstoprobabilityvaluesiscalledthe
probabilitymassfunction(pmf).Sincethesetofoutcomesislimited,wespeakofadiscrete
probabilitydistribution.
Ifyoudealwithresultsfromacontinuousrange(likerealvalues),youmustsomehowderivea
probabilitydensityfunctionf(x),thatallowsyoutocomputehowlikelyanoutcomeliesbetween
twogivenbounds.Iftheboundsareveryclosetoeachother,theprobabilityisroughlygivenby
f(x)*(upperlimitlowerlimit),butforarbitrarylimitsyouneedtoknowtheintegralfunctionP(x)of
f(x).TheprobabilityofatestresulttoliebetweenanytwolimitsisthengivenbyP(upperlimit)
P(lowerlimit).Averyfamousandfundamentalexampleisthatofthebellcurvedescribinganormal
distribution.Thisfunction,initspurestform,isanalyticallygivenbythefunction
f(x)=exp(x*x)/sqrt(pi),
anditsintegralfunction(actuallytwiceitsintegral)isimplementedaserrorfunctionerf(x)in
SpeedCrunch.
Sinceweassumeoutcomestobenumeric,questionslikehowlikelyisitthattheoutcomeisbelowa
bound(notethattheprobabilisticmassfunctiononlyanswershowlikelyisitthattheoutcomeis
exactlyagivenvalue),andasanextension,howlikelyisit,thataresultliesbetweentwogiven
boundsarise.Inthecontinuouscase,wesawthattheintegralofaprobabilityfunctioncantellthe
answer.Inthediscretecase,wecanderiveasimilarfunctionfromadistributionfunction,calledthe
cumulativedistributionfunction(cdf).Andagain,asimpledifferencetellsthedesiredanswer:
cdf(upperlimit)cdf(lowerlimit)istheprobability,thatatestresultislessorequaltoupperlimit,
butgreaterthanthelowerlimit.
distributionsofseriesoftests

Uptonow,wetalkedaboutasingletestorprobabilisticexperimentonly.Inpractice,weoftenhaveto
dealwithaseriesoftests.Iftheoutcomeofonetestdoesnotinfluencethefollowingtest,thetestsare
saidtobeindependent.Castingadiceisanexampleofthis,butdrawingacardfromadeckisnot,
becausetheremovedcardmodifiestheprobabilitiesofthefollowingtest.
Theoutcomeofaseriesoftestsisnaturallynotasinglevalueanymore,butatupleofthesizeofthe
testcount.Inthediscretecase,again,weareabletoassignanysuchtupleaprobability,nowbasedon
theprobabilitiesofeachtest.Sincethisvaluecanbecomputed,statisticianshavedevelopedatheory
aroundtestseriesandderivedprobabilitydistributionsontuplesratherthanonsingleoutcomes,and
clarifiedhowthesedistributionsdependonthatofthetests.Someofthesimplerdistributionshave
beenimplementedinSpeedCrunch.
Associatedwithdistributionsaresomecharacteristicvalues.Oneoftheseisthemeanorexpected
value.Thisvalueisthe(expected)averageoutcomeinaverylongseriesoftests.Thesecondsuch
valueisthevarianceofadistribution(roughly:theaverageofthesquaresofdistancestothemean),
thatsayssomethingaboutthespreadofthedistribution.
Thebinominaldistributionisbasedonaseriesofindependentandequalyes/notests.Thelikeliness
ofacertaineventineachtestistheprobabilityp.Theconcretenatureofthetestisofnoimportance,
justpandtheassumedindependence.Thebinominaldistributiontellshowlikelyitisthatexactlyr
eventsoccurinaseriesofntests.Theassociatedcdffunctionreturnshowlikelyitisthatatmostr

eventsoccur.
Thehypergeometricdistributionhandlescaseswhereyouknowthenumberofaspecificeventina
seriesoftestsinadvance.Itanswersthequestion,howlikelyyouwillhaveacertainamountofthese
eventsinanygivensubsetofthesetests.Theassociatedcdffunctiontellshowlikelytherewillbeup
toagivencountofeventsinanysubsetoftheseries.
ThePoissondistributionhandlesthecasewhereyouknowtheaverageoccurrenceofan
(independent)eventinagiveninterval(oftenatimeinterval),andassumeithasthesamevariance,
andyounowwanttoknow,howlikelytheoccurrenceofexactlyneventsinthisintervalis.The
associatedcdffunctiontellshowlikelytherewillbeuptoaneventsinthisinterval.

functionlist
Here'sanalphabeticallistofimplementedfunctions:
abs(x)

returns|x|,turningnegativenumbersintopositiveones,andleavingpositiveonesunchanged.
abs(1)
and
abs(1)
bothyield1.
acos(x)

returnsthearccos(x),theinversefunctiontocosy.
Thereturnvalueisdependentonthedegreesetting;ifdegreesisenabled,thereturnvalueisfrom
therange0<=result<=180,elsefrom0<=result<=.
Thearccos(x)istheprincipalsolutiontotheequationcos(y)=x.Othersolutionsare(radians)

arccos(x)+2*n*forallintegersn;

arccos(x)+2*n*forallintegersn.

or(degrees):

arccos(x)+n*360forallintegersn;

arccos(x)+n*360forallintegersn.

Thevalidrangeoftheparameteris1<=x<=1.
Example:
acos(0.5)
Relatedtothisfunctionisthearcsec(x),foundby
acos(1/x)
and(x1;x2;...)

PerformsabitwiselogicalANDonthesubmittedparameter(s)(oneormore).

Allparametershavetobeintegersfromtherange2255to+22561(signedorunsigned256bit
integers).Theresultisfrom2255to+22551(signedinteger).
Notethatand(x)isnottheidentity,becausetheunsigned+2255ismappedtothesigned2255,for
example.
Anerrorisreturned,ifaparameterisnotfromthevalidrange.
Example:
hex(and(29;0x33;0b11111))
arcosh(x)

computestheareahyperboliccosineofx,theinversefunctiontocoshy.
arcosh(x)isthepositivesolutiontocosh(y)=x.
Exceptfor1,thereexistsasecondsolutiontothisequation:arcosh(x).
Theparameterxhastobe>=1.
Example:
arcosh(4.7)
Relatedtothisfunctionisarsech,theareahyperbolicsecant,whichcanbecomputedby
arcosh(1/x)
arsinh(x)

computestheareahyperbolicsineofx,theinversefunctiontosinhy.
arsinh(x)isthe(only)solutiontosinh(y)=x.
Example:
arsinh(0.47)
Relatedtothisfunctionisarcsch,theareahyperboliccosecant,whichcanbecomputedby
arsinh(1/x)
artanh(x)

computestheareahyperbolictangensofx,theinversefunctiontotanhy.
artanh(x)istheonlysolutiontotanh(y)=x.
Theparameterxhastofulfil1<x<1.
Example:
artanh(0.7)
Relatedtothisfunctionisarcoth,theareahyperboliccotangent,whichcanbecomputedby
artanh(1/x)

asin(x)

returnsthearcsin(x).theinversefunctiontosin.
Thereturnvalueisdependentonthedegreesetting;ifdegreesisenabled,thereturnvalueisfrom
therange90<=result<=90,elsefrom/2<=result<=/2.
Thearcsin(x)istheprincipalsolutiontotheequationsin(y)=x.Othersolutionsare(radians)

arcsin(x)+2*n*forallintegersn;

arcsin(x)+(2*n+1)*forallintegersn.

or(degrees):

arcsin(x)+n*360forallintegersn;

arcsin(x)+n*360+180forallintegersn.

Thevalidrangeoftheparameteris1<=x<=1.
Example:
asin(0.5)
Relatedtothisfunctionisthearccsc(x),foundby
asin(1/x)
atan(x)

returnsthearctan(x),theinversefunctiontotany.
Thereturnvalueisdependentonthedegreesetting;ifdegreesisenabled,thereturnvalueisfrom
therange90<result<90,elsefrom/2<result</2.
Thearctan(x)istheprincipalsolutiontotheequationtan(y)=x.Othersolutionsare
(radians):arctan(x)+n*forallintegersn;
or
(degrees):arctan(x)+n*180forallintegersn;
Example:
atan(500)
Relatedtothisfunctionisthearccot(x),foundby
atan(1/x)
average(x1;x2;...)

computestheaverage,ormeanvalueofthesubmittedparameter(s)(oneormore).
Example:
average(13.5;3*3;0;4)
bin(n)

Displaysninbinaryformat,withoutgloballychangingtheoutputformat.Afractionalpartofniscut

offbeforeconversion,andtheremainingintegralparthastobefromtherange2255to+22561.
Example:
bin(1000/13)
returns0b1001100,thebinaryencodingof76.
binomcdf(max;trials;p)

trialsisanonnegativeinteger,maxapositiveinteger,and0<=p<=1.
Thisfunctiondeterminestheprobability,thatinaseriesof'trials'independentprobabilistictests,each
resultinginaneventwithprobabilityp,atmost'max'eventsoccur.
binommean(trials;p)

trialsisanonnegativeinteger,0<=p<=1.
Ifyouhave'trials'independenttests,eachofthemresultinginagiveneventwithprobabilityp,this
numbertellsyou,howmanyeventsyouwillhaveontheaverage.
binompmf(hits;trials;p)

trialsisanonnegativeinteger,hitsapositiveinteger,and0<=p<=1.
Thisfunctiondeterminestheprobability,thatinaseriesof'trials'independentprobabilistictests,each
resultinginaneventwithprobabilityp,exactly'hits'eventsoccur.
binomvar(trials;p)

trialsisanonnegativeinteger,0<=p<=1.
Thevarianceofthebinominaldistributionfunction,basedon'trials'independenttests,eachresulting
inaneventwithprobabilityp.Inotherwords,ittellshow'good'theresultofbinommeanis.
cbrt(x)

computesthethird(cubic)rootofx.Thisfunctionoperatesonnegativenumbersaswell.Theinverse
functionisy^3.
Example:
cbrt(27)
is3.
ceil(x)

Findsthesmallestintegergreaterorequaltox,theceilingofx.
ceil(2.4)
is2,
ceil(2.4)
is3,and

ceil(2)
is2.
cos(x)

evaluatesthecosineofx.Theresultisdependentonthedegreesetting.Ifdegreesisactive,the
parameterxisassumedtobeanarcfroma360circle,otherwiseafullcircleisrepresentedby2*.
Theinversefunctionisacos(y).
Althoughthecosineismathematicallydefinedforallx,forxbeyondapproximately1e77,the
periodicityofthecosineisnotrecognizedanymore,soSpeedCrunchissuesanerrorthen.Example:
cos(1000)
cosh(x)

Findsthehyperboliccosineofx.
Thisfunctionoverflowsfor|x|>1236190959.52...
Theinversefunctionisarcosh.
Example:
cosh(7.22)
cot(x)

evaluatesthecotangentofx.Theresultisdependentonthedegreesetting.Ifdegreesisactive,the
parameterxisassumedtobeanarcfroma360circle,otherwiseafullcircleisrepresentedby2*.
Althoughthecotangentismathematicallydefinedforallx,forxbeyondapproximately1e77,the
periodicityofthecotangentisnotrecognizedanymore,soSpeedCrunchissuesanerrorthen.
Example:
cot(1000)
csc(x)

evaluatesthecosecantofx.Theresultisdependentonthedegreesetting.Ifdegreesisactive,the
parameterxisassumedtobeanarcfroma360circle,otherwiseafullcircleisrepresentedby2*.
Althoughthecosecantismathematicallydefinedforallx,forxbeyondapproximately1e77,the
periodicityofthecosecantisnotrecognizedanymore,soSpeedCrunchissuesanerrorthen.
Example:
csc(1000)
dec(x)

Displaysxindecimalformat,withoutgloballychangingtheoutputformat.Thisfunctionisuseful
whenyouchangedtheoutputformattoabinaryformat.
Example:
dec(1000/13)

returns76.923..,evenifyouhaveactivatedhexoutputmodeforinstance.
degrees(x)

convertsananglemeasuredinradiantodegrees.Thisfunctionisespeciallyuseful,ifyouwantto
overridethecurrentanglemodeforjustoneexpression.Example:
degrees(acos(0.5))
tan(degrees(1))
degrees(pi)
erf(x)

determinesthenormalizederrorfunctionofx,thecumulativedistributionfunctionofthenormal
distribution(bellcurve,Gaussiandistribution).
Analytically,itistheintegralfunctionof2*exp(x*x)/sqrt().
Example:
erf(0.5)
erfc(x)

determinesthenormalizedcomplementaryerrorfunctionofx,relatedtothecumulativeprobability
functionofthenormaldistribution(bellcurve,Gaussiandistribution).Erfc(x)+erf(x)isalways1.
Example:
erfc(0.5)
erfcunderflowsforx>35159.507..
exp(x)

evaluatesthenaturalexponentialfunctiontothebasee==2.71828...
Theinversefunctionisln(x).
exp(x)overflows/underflowsfor|x|>1236190958.83...
Example:
exp(ln2+ln3)
floor(x)

Findsthegreatestintegerlessorequaltox,thefloorofx.
floor(2.4)
is3,
floor(2.4)
is2,and
floor(2)

is2.
frac(x)

cutsofftheintegralpartofarealnumber.
frac(2.3)
returns0.3.
gamma(x)

(x),equivalentto(x1)!.
gcd(n1;n2;...)

returnsthegreatestcommondivisoroftheintegersn1,n2...(2ormore)
Youcanusethisfunctiontoreducearationalnumber.Ifarationalnumberisgivenasp/q,its
reducedformis(p/gcd(p;q))/(q/gcd(p;q)).
Relatedtothegcdisthelcmfunction(leastcommonmultiplier).Youcanfindthelcmby:
lcm(n1;n2)=n1*n2/gcd(n1;n2),e.g
720*486/gcd(720;486)
is19440,thelcmof720and486
geomean(x1;x2;...)

findsthegeometricmeanofthepositivenumbersx1,x2...(oneormoreparameter).
Nonpositiveparametersarenotallowed.
Example:
geomean(17;ln5;8+2)
hex(n)

Displaysninhexagesimalformat,withoutgloballychangingtheoutputformat.Afractionalpartofn
iscutoffbeforeconversion,andtheremainingintegralparthastobefromtherange2255to+22561.
Example:
hex(1000/13)
returns0x4C,theencodingof76.
hypercdf(max;total;hits;trials)

Allparametersareintegers,0<=max<=hits<=total,0<=trials<=total,and0<total.
Assumethereare'hits'eventsinaseriesof'total'tests.Thenthisfunctionevaluatestheprobability,
thatyouwillfinduptomaxeventsoftheminasubseriesof'trials'tests.

hypermean(total;hits;trials)

Allparametersareintegers,0<=hits<=total,0<=trials<=total,and0<total.
Assumethereare'hits'eventsinaseriesof'total'tests.Thenthisfunctionevaluatestheexpected
countofeventsinasubseriesof'trials'tests.
hyperpmf(count;total;hits;trials)

Allparametersareintegers,0<=max<=hits<=total,0<=trials<=total,and0<total.
Assumethereare'hits'eventsinaseriesof'total'tests.Thenthisfunctionevaluatestheprobability,
thatyouwillfindexactlycounteventsinasubseriesof'trials'tests.
hypermean(total;hits;trials)

Allparametersareintegers,0<=hits<=total,0<=trials<=total,and0<total.
Assumethereare'hits'eventsinaseriesof'total'tests.Thenthisfunctionevaluatesthevarianceofthe
countofeventsinasubseriesof'trials'tests.Or,inotherwords,ittells,how'good'theresultof
hypermeanismatchedontheaverage,ifyourepeatyoursubseriesoftrialsveryoften.
idiv(dividend;divisor)

Evaluatestheintegerpartofdividend/divisor.Theresultisalwaysexact.
SinceSpeedCrunchcanholdintegersupto78digitsonly,thisfunctionoverflowseveniftheordinary
divisionoperator/wouldyieldanapproximate(buthuge)quotient.
Itispossibletoapplytheidivfunctiontononintegersaswell,butbeawarethatroundingerrors
mightleadtooffbyoneerrors.Ifidivdetects,thataresultdependsonthevalidityoftheguarddigits,
itreturnsaNaNasawarning,e.g.idiv(1/3*3;1)isNaN,becausethefirstparameteris0.99...,and
idivcannotsafelydecidewhethertoreturn0or1.
Examples:
idiv(17;3)
is5.
idiv(1.23;0.034)
is36.
int(x)

returnsthe(signed)integerpartofx.
Example:
int(2.3)
return2,
int(0.3)
returns0.

lg(x)

returnsthebase2logarithmofx.
xhastobepositive.
Examples:
lg(16)
is4.
lg(3.1)
is1.632..
ln(x)

returnsthenaturallogarithmofx,thebaseise=2.71828...
xhastobepositive.
Theinversefunctionisexp(y).
Examples:
ln(0.2)
lngamma(x)

evaluatesln((x)),orln((x1)!),forpositivex.
Thefactorialor(x)isgrowingtremendously,andoverflowsformoderatevaluesalready.Butthis
functionwillevenreturnaresult,whenthe!operatoroverflows.
Example:
lngamma1e1000/ln10
showsthat(101000)!hasabout9.996*101002decimaldigits.
log(x)

returnsthebase10logarithmofx.
xhastobepositive.
Examples:
log(10)
is1.
log(3.1)
is0.49136...
mask(n;bits)

returnsthelower'bits'bitsoftheintegern.Theresultisalwaysunsigned.
nhastobefrom2255to+22561(signedorunsigned256bitintegers),bitsisanintegerrangingfrom

1to255inclusive.
Oneapplicationofthisfunctionistofindthetwo'scomplementrepresentationofavalue.So
hex(mask(1;16))
returns0xFFFF,the16bittwo'scomplementbitpatternof1.
max(x1;x2..)

takesoneormoreparameter(s).
returnsthemaximumvalueofthesubmittedparameters.
Example:
max(17;log1000;exp(3))
min(x1;x2..)

takesoneormoreparameter(s).
returnstheminimumvalueofthesubmittedparameters.
Example:
min(0.4;log0.1;exp(3))
mod(value;modulo)

evaluatesvaluemodmodulo,thatistheremainderafterfindingtheintegerquotientvalue/modulo.
Thisfunctionalwaysreturnsanexactresult,iftheparametersareexact.
'modulo'hastobenonzero.
Iftheremainderisnonzero,ittakesthesignofvalue.
Youcanusethisfunctionwithnonintegersaswell,butroundingerrorsmightleadtooffbyone
errors.
Thisfunctioncanpotentiallybeverytimeconsuming,somodisrestrictedtoatmost250division
loops.
Therelationx=idiv(x;y)*y+mod(x;y)holds.
Examples:
mod(17;3)
is2,and
mod(1.23;0.034)
is0.006(exact)
nCr(x1;x2)

Forintegerparametersthisfunctionisequal

tothenumberofcombinations(orderisofnoimportance)ofx2elementsfromanx1sizedset
ofelements;

tothebinominalcoefficientx1overx2.

Forarbitraryrealvaluedx1,x2theresultis1/((x1+1)*B(x2+1,x1x2+1)),whereB(a,b)isthe
completeBetafunction.
Examples:
Howmanycombinationsof12elementsoutof17arethere:(6188)
nCr(17;12)
Findthe(binominal)coefficientofxintheseriesexpansionofsqrt(1+x):(0.0625)
nCr(0.5;3)
EvaluatethecompleteBetafunctionfora=2.3andb=7.6:(0.00915..)
1/(7.6+2.31)/nCr(7.6+2.32;2.31)
not(n)

Evaluatesthebitwise(one)complementofn.Theresultisasigned256bitinteger.
nhastobeanintegerfromtherange2255to+22561(signedorunsigned256bitintegers).
Examples:
not(1)
is0.
hex(mask(not(0xA77);32))
returnsthe32bitencodingofnot(0xA77)==0xFFFFF588
nPr(x1;x2)

Forintegerparametersthisfunctionisequal

tothenumberofpermutations(orderisofimportance)ofx2elementsfromanx1sizedsetof
elements;

thefallingfactorial(orPochhammersymbol)x1*(x11)*..*(x1x2+1).

Forarbitraryrealvaluedx1,x2theresultis(x1+1)/(x2),wherethepolesofthefunctionare
handledcorrectly.
Examples:
Howmanypermutationsof12elementsoutof17arethere:(2964061900800)
nPr(17;12)
Findtheproduct2.5*1.5*0.5*...*(2.5):(3.515625)
nPr(2.5;6)
oct(n)

Displaysninoctalformat,withoutgloballychangingtheoutputformat.Afractionalpartofniscut
offbeforeconversion,andtheremainingintegralparthastobefromtherange2255to+22561.

Example:
oct(1000/13)
returns0o114,theoctalencodingof76.
or(x1;x2;...)

PerformsabitwiselogicalORonthesubmittedparameter(s)(oneormore).
Allparametershavetobeintegersfromtherange2255to+22561(signedorunsigned256bit
integers).Theresultisfrom2255to+22551(signedinteger).
Notethator(x)isnottheidentity,becausetheunsigned+2255ismappedtothesigned2255,for
example.
Anerrorisreturned,iftheparametersarenotfromthevalidrange.
Example:
hex(or(29;0x33;0b11111))
poicdf(events;avgevnts)

'events'isanonnegativeinteger,'avgevents'apositiverealnumber.
Ifyouhaveontheaverage'avgevents'independenteventsinaninterval,thisfunctionreturnsthe
probability,thatyouwillseeupto'events'eventswhenyoutestaninterval.
poimean(avgevents)

avgevents>=0
trivial,returnstheaveragenumberofeventsinaninterval,whenthisaverageis'avgevents'
poipmf(events;avgevnts)

'events'isanonnegativeinteger,'avgevents'apositiverealnumber.
Ifyouhaveontheaverage'avgevents'independenteventsinaninterval,thisfunctionreturnsthe
probability,thatyouwillseeexactly'events'eventswhenyoutestaninterval.
poivar(avgevents)

avgevents>=0
Trivial,thePoissondistributionassumes,thatthevarianceequalstheexpectedvalue'avgevents'.
radians(x)

convertsananglemeasuredindegreestoradians.Thisfunctionisespeciallyuseful,ifyouwantto
overridethecurrentanglemodeforjustoneexpression.Example:
radians(acos(0.5))
tan(radians(1))
radians(180)

round(x;digits)

roundsxto'digits'decimalplacesafterthedecimalpoint.
'digits'hastobeaninteger.
Theroundingistonearest.
Examples:
round(pi;2)
yields3.14.
round(2/3;5)
gives0.66667.
Ifonlyasingledigit'5'wascutoff,thenroundingissuchthatthedigitbeforeitiseven.
round(1.5;0)
is2,but
round(0.5;0)
is0.
Asanextension,'digits'maybenegative.Inthiscase,roundingtakesplaceintheintegerpartofx.
Thisroundsavaluetofullthousands:(23000)
round(22788.76;3)
sec(x)

evaluatesthesecantofx.Theresultisdependentonthedegreesetting.Ifdegreesisactive,the
parameterxisassumedtobeanarcfroma360circle,otherwiseafullcircleisrepresentedby2*.
Althoughthesecantismathematicallydefinedforallx,forxbeyondapproximately1e77,the
periodicityofthesecantisnotrecognizedanymore,soSpeedCrunchissuesanerrorthen.Example:
sec(1000)
shl(n,bits)

Shiftsthebitpatternofn'bits'bittotheleft,if'bits'>=0,otherwiseshiftsnarithmeticallyby'bits'to
theright.
255<=bits<=255,andnhastobeanintegerfromtherange2255to+22561(signedorunsigned
256bitintegers).Theresultisfrom2255to+22551(signedinteger).
Onashiftleft,zerobitsarefedintotheright,andshiftedoutbitsaredroppedontheleft.Onashift
right,bit255(theleftmostbit)iscopiedandshiftedinfromtheleft,andshiftedoutbitsontheright
aredropped.
Anerrorisreturned,iftheparametersarenotfromthevalidrange.
Example:
shl(1;3)

shl(0x33721655617;1)
Thelastoperationiseffectivelyashiftright.
shr(n,bits)

Shiftsthebitpatternofn'bits'bittotheright,if'bits'>=0,otherwiseshiftsnarithmeticallyby'bits'
totheleft.
255<=bits<=255,andnhastobeanintegerfromtherange2255to+22561(signedorunsigned
256bitintegers).Theresultisfrom2255to+22551(signedinteger).
Onashiftleft,zerobitsarefedintotheright,andshiftedoutbitsaredroppedontheleft.Onashift
right,bit255(theleftmostbit)iscopiedandshiftedinfromtheleft,andshiftedoutbitsontheright
aredropped.
Anerrorisreturned,iftheparametersarenotfromthevalidrange.
Example:
shr(2^255;3)
shr(0x33721655617;1)
Thelastoperationiseffectivelyashiftleft.
sign(x)

returnsthesignofx,1ifnegative,1ifpositive,and0for0
Example:
sign(sin10000)
sin(x)

evaluatesthesineofx.Theresultisdependentonthedegreesetting.Ifdegreesisactive,the
parameterxisassumedtobeanarcfroma360circle,otherwiseafullcircleisrepresentedby2*.
Theinversefunctionisasin(y).
Althoughthesineismathematicallydefinedforallx,forxbeyondapproximately1e77,theperiodicity
ofthesineisnotrecognizedanymore,soSpeedCrunchissuesanerrorthen.Example:
sin(1000)
sinh(x)

Findsthehyperbolicsineofx.
Thisfunctionoverflowsfor|x|>1236190959.52...
Theinversefunctionisarsinh.
Example:
sinh(7.22)

sqrt(x)

computesthesquarerootofx.Notdefinedforx<0.
sqrt(x)istheotherroottotheequationx=y*y.
Theinversefunctionisy^2.
Example:
sqrt(64)
is8.
tan(x)

evaluatesthetangentofx.Theresultisdependentonthedegreesetting.Ifdegreesisactive,the
parameterxisassumedtobeanarcfroma360circle,otherwiseafullcircleisrepresentedby2*.
Theinversefunctionisatan(y).
Althoughthetangentismathematicallydefinedforallx,forxbeyondapproximately1e77,the
periodicityofthetangentisnotrecognizedanymore,soSpeedCrunchissuesanerrorthen.Example:
tan(1000)
tanh(x)

Findsthehyperbolicsineofx.
Theinversefunctionisartanh.
Example:
tanh(7.22)
trunc(x;digits)

truncatesxafter'digits'decimalplacesbehindthedecimalpoint.
'digits'hastobeaninteger.
Examples:
trunc(pi;2)
yields3.14.
trunc(2/3;5)
gives0.66666.
Asanextension,'digits'maybenegative.Inthiscase,truncationtakesplaceintheintegerpartofx.
Thistruncatesavalueafterthethousands:(22000)
trunc(22788.76;3)
unmask(n;bits)

takesthelower'bits'bitsofnandsignextendsthemtofull256bit,meaningbitnumber'bits'1is

copiedtoallupperbits.
nhastobeanintegerfromtherange2255to+22561(signedorunsigned256bitintegers),and'bits'
isanintegerwith1<=bits<=255.
Thisfunctioncanreverttheeffectofamaskfunctioninmanycases,that'swhyitisnamedso.
Ifyouaregivenanegativeintegerintwo'scomplementnotation,itisnotpossibletoenteritdirectly
asaconstant,becausebinary,hexoroctalencodedconstantsarealwaysrecognizedasunsignedin
SpeedCrunch.
Thisfunctionallowsyoutoovercomethisproblem.Itcanconvertanunsignedintoasignedinteger.
Examples:
unmask(0xFFFF;16)
yields1,
unmask(0x1FFF;16)
yields0x1FFF,becausebit15iszero,sothesignextensionsimplygivestheoperand.
The'bits'parameterneednotbeapoweroftwo.Thisgives2:
unmask(0x3FE;10),
andiftheoperandhasabitlengthgreaterthan'bits',theupperbitsaremasked:
unmask(0x10FF;8)
yields1,becauseallupperbitsbeyondtheeighthareclearedbeforetheoperandisextended.
xor(x1;x2;...)

PerformsabitwiselogicalXORonthesubmittedparameter(s)(oneormore).
Allparametershavetobeintegersfromtherange2255to+22561(signedorunsigned256bit
integers).Theresultisfrom2255to+22551(signedinteger).
Notethatxor(x)isnottheidentity,becausetheunsigned+2255ismappedtothesigned2255,for
example.
Anerrorisreturned,iftheparametersarenotfromthevalidrange.
Example:
hex(xor(29;0x33;0b11111))

You might also like