Square root by hand: Difference between revisions

→‎{{header|J}}: support decimal fraction arguments and include more examples
(J)
(→‎{{header|J}}: support decimal fraction arguments and include more examples)
Line 388:
<syntaxhighlight lang=J>srdig=: {{
if. x > 1{9!:36'' do. 9!:37]x 1}9!:36'' end.
<.@%:y*10^2x*need+x-#":<.@%:y*10^2x*need=.0>.x-#":<.@%:y=.x:y
}}</syntaxhighlight>
 
Example use: 1000x digits of the square root of 2y:
<syntaxhighlight lang=J> 1000 srdig 2
1414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572735013846230912297024924836055850737212644121497099935831413222665927505592755799950501152782060571470109559971605970274534596862014728517418640889198609552329230484308714321450839762603627995251407989687253396546331808829640620615258352395054745750287759961729835575220337531857011354374603408498847160386899970699004815030544027790316454247823068492936918621580578463111596668713013015618568987237235288509264861249497715421833420428568606014682472077143585487415565706967765372022648544701585880162075847492265722600208558446652145839889394437092659180031138824646815708263010059485870400318648034219489727829064104507263688131373985525611732204024509122770022694112757362728049573810896750401836986836845072579936472906076299694138047565482372899718032680247442062926912485905218100445984215059112024944134172853147810580360337107730918286931471017111168391658172688941975871658215212822951848847
1000 srdig 0.2
4472135954999579392818347337462552470881236719223051448541794490821041851275609798828828816757564549939016352301547567008506535448894147727172720243066905417733556346383758331622553290645279713161071522700835067570006846784828128884172865078194505185254457752599034804881363223551817818996984742781459457796964177283085379788198263387154039497357768850179508265912366353842999954849603060868230071915336665024997630356278816001124841710487084471112212612685640468186663965867919492704542402683499228405271809475771008779374122271320091514279913191133913835129156443905000121078462468010018573529751059444113532507332148971707010524661356989266844484635274554053264815360208886631651467011786196272452686397372943893979940361637904852891924069044282384465825196392651622208340991614096240806911989887013711103711145024777283310020524872625142048899237578849365806808949432230911446403475353180921837059151207155968796108310761558128787279446057512125998964427704354697184907030242092691110081414455744
1000 srdig 3
1732050807568877293527446341505872366942805253810380628055806979451933016908800037081146186757248575675626141415406703029969945094998952478811655512094373648528093231902305582067974820101084674923265015312343266903322886650672254668921837971227047131660367861588019049986537379859389467650347506576050756618348129606100947602187190325083145829523959832997789824508288714463832917347224163984587855397667958063818353666110843173780894378316102088305524901670023520711144288695990956365797087168498072899493296484283020786408603988738697537582317317831395992983007838702877053913369563312103707264019249106768231199288375641141422016742752102372994270831059898459475987664288897796147837958390228854852903576033852808064381972344661059689722872865264153822664698420021195484155278441181286534507035191650016689294415480846071277143999762926834629577438361895110127148638746976545982451788550975379013880664961911962222957110555242923723192197738262561631468842032853716682938649611917049738836395495938
</syntaxhighlight>
 
=={{header|Java}}==
{{trans|D}}
6,962

edits