JuliaMath / JuliaMath/SpecialFunctions.jl

erfinv(::BigFloat) enters infinite loop

Open
#338 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
381
Forks
113
Avg merge
1d 23h
Merged PRs (30d)
1

Description

What the title says. The problem seems to be with the Newton's method implementation in lines 432-437 of `erf.jl`.
```julia
while true # Newton iterations
Δx = sqrtπhalf * (erf(x) - y) * exp(x^2)
x -= Δx
abs(Δx) < tol && break
i += 1
end
```

I changed the loop to a finite one and logged the value if the loop ran 10000 iterations. The following vector of logged values should be useful for testing; I tried out a few of them and I indeed got stuck in an infinite loop.

```julia
testvals = BigFloat[
0.9395615430047861149631671651150099933147430419921875
0.9404791642273144791630556937889195978641510009765625
0.941154782589318283925194918992929160594940185546875
0.941194121590200882820909100701101124286651611328125
0.9412980378578670315192766793188638985157012939453125
0.941392615179371006206565652973949909210205078125
0.941392812046334181985685063409619033336639404296875
0.94139837911296542216632587951608002185821533203125
0.9414025544129389633241089541115798056125640869140625
0.9415072243757318659618249512277543544769287109375
0.94273997012758226077266954234801232814788818359375
0.94381178738070303779750247485935688018798828125
0.943972361330209341900854269624687731266021728515625
0.944223446113291675629852761630900204181671142578125
0.9453736053204682132644620651262812316417694091796875
0.946312350179528749549717758782207965850830078125
0.946323811567157502366853805142454802989959716796875
0.9463289244771975194936430852976627647876739501953125
0.947031315947979290825742282322607934474945068359375
0.94708145512168240287564913160167634487152099609375
0.94710166732902933972582104615867137908935546875
0.9471017681293629753014329253346659243106842041015625
0.947101809092823376801106860511936247348785400390625
0.9471018090933307487233605570509098470211029052734375
0.9595686225979311867462229201919399201869964599609375
0.960509447616531009117579742451198399066925048828125
0.961210152975662257546218825154937803745269775390625
0.96135182755843029411835232167504727840423583984375
0.96925241017819718791770355892367660999298095703125
0.96925289771273437366971847950480878353118896484375
0.9709004860132586234300333671853877604007720947265625
0.9755876142253168126217133249156177043914794921875
0.97578296877193881897483151988126337528228759765625
0.9758005920577697001050410108291544020175933837890625
0.975802516708709877235605745227076113224029541015625
0.9758305024185693898886029273853637278079986572265625
0.977078599237291456347520579583942890167236328125
0.979976681761565604489305769675411283969879150390625
0.9799988930055489877446461832732893526554107666015625
0.9800000199755045660054975087405182421207427978515625
0.980583608440868115252442294149659574031829833984375
0.98058719105351688227756312699057161808013916015625
0.9826256538226498804533548536710441112518310546875
0.9829708819779285899898013667552731931209564208984375
0.98297528779954479460911898058839142322540283203125
0.98297528779969933765414680237881839275360107421875
0.9829752878028144014166400665999390184879302978515625
0.9829752896751193791402556598768569529056549072265625
0.9850676114860466014988560345955193042755126953125
0.985067882703463570948088090517558157444000244140625
0.9850679073903017002322712869499810039997100830078125
0.98521738021860105760652004391886293888092041015625
0.985217380218646354705924750305712223052978515625
0.9852173802186514617318380260257981717586517333984375
0.985217380252479291158351770718581974506378173828125
0.9852921104608098890054179719300009310245513916015625
0.98529211663261673237457216600887477397918701171875
0.9852921166326196189544361914158798754215240478515625
0.9852923040853178715536841991706751286983489990234375
0.9852932568035921434557167231105268001556396484375
0.985328652894947421003735144040547311305999755859375
0.98532947909813461961903158226050436496734619140625
0.9853361764390218269227261771447956562042236328125
0.9853481048609704640028894573333673179149627685546875
0.9853481688143197469997858206625096499919891357421875
0.985348256052317683639785172999836504459381103515625
0.9853484475032530109928075034986250102519989013671875
0.9853575109948453647490396178909577429294586181640625
0.9853575129523759468241905778995715081691741943359375
0.9853576117629259112362660744111053645610809326171875
0.98535766102839605906638098531402647495269775390625
0.9853621819608215925967442672117613255977630615234375
0.9853621820207181247752714625676162540912628173828125
0.98536218206462766744380132877267897129058837890625
0.9853645162913473587451562707428820431232452392578125
0.985365683138843539978779517696239054203033447265625
0.9853656852900189999644453564542345702648162841796875
0.9853656852901242491071798212942667305469512939453125
0.9853656853011008021070438189781270921230316162109375
0.985366780061813329893993795849382877349853515625
0.985366815741756330027101284940727055072784423828125
0.985366848485556889869485530653037130832672119140625
0.985366848620548463344448464340530335903167724609375
0.985366851733868731599841339630074799060821533203125
0.98536685190618999996559068677015602588653564453125
0.9853668524849410470523025651345960795879364013671875
0.985366852903780898742525096167810261249542236328125
0.9853668529040595647217060104594565927982330322265625
0.9853668529753181193342470578500069677829742431640625
0.9853668530055703644876530233887024223804473876953125
0.9853668530319656948535111951059661805629730224609375
0.985366853032100475928700689109973609447479248046875
0.9853668530376811229842815009760670363903045654296875
0.9853668530376891165900588021031580865383148193359375
0.9853668530422454718831204445450566709041595458984375
0.9853668530429364746936471419758163392543792724609375
0.9853668530443380202399339395924471318721771240234375
0.985366853045487989248840676737017929553985595703125
0.9853668530464607666630172388977371156215667724609375
0.985366853046557356066159627516753971576690673828125
0.985366853046591995024527932400815188884735107421875
0.9869443209900523594768628754536621272563934326171875
0.9881387761475435294045155387721024453639984130859375
0.9882922922542884958119202565285377204418182373046875
0.98842848901661994887035689316689968109130859375
0.989407889699055687060536001808941364288330078125
0.989410187040000277391982308472506701946258544921875
0.9894262894574394895386149073601700365543365478515625
0.989466931396076887494928087107837200164794921875
0.99120334921834807317964077810756862163543701171875
0.993743631946243599628587617189623415470123291015625
0.9941226489001546706703038580599240958690643310546875
0.99439336808072642526212803204543888568878173828125
0.9969251751809229400436151991016231477260589599609375
0.997520356340249048088253402966074645519256591796875
-0.9975408366895468503798838355578482151031494140625
-0.997649815280502227921033409074880182743072509765625
-0.997650928045452634052026041899807751178741455078125
-0.997657882289859632152229096391238272190093994140625
-0.997658782376682484738239509169943630695343017578125
-0.99765884978388985615538331330753862857818603515625
-0.9976590831600071762608195058419369161128997802734375
-0.9976591294388572617179988810676150023937225341796875
-0.9976591394406375545855780728743411600589752197265625
-0.9976591511256682753838731514406390488147735595703125
-0.9976591562058432227644289014278911054134368896484375
-0.9976591581625544602474064959096722304821014404296875
-0.997659165754163357320294380770064890384674072265625
-0.997659165934034586342704642447642982006072998046875
-0.9976591664643226220476890375721268355846405029296875
-0.9976591668728438389024404386873356997966766357421875
-0.997659167255691148312735094805248081684112548828125
-0.997659167275050773326938724494539201259613037109375
-0.9976591672781849329254555414081551134586334228515625
-0.997659167280958936174783957540057599544525146484375
-0.99765916728952408476516211521811783313751220703125
-0.9976591672933732279915375329437665641307830810546875
-0.9976591672934616017442976954043842852115631103515625
-0.997659167295882109982585461693815886974334716796875
-0.9976591672963290857722995497169904410839080810546875
-0.997659167296746307584953683544881641864776611328125
-0.99765916729676096252887873561121523380279541015625
-0.9976591672967682900008412616443820297718048095703125
0.99812481703780786546076342347078025341033935546875
0.99856433274401723565460997633635997772216796875
0.9990627984559738994363442543544806540012359619140625
0.9990971710365992297653292553150095045566558837890625
0.999510657212258291082207506406120955944061279296875
0.9995517324572791295622664620168507099151611328125
0.999649029513553610826193107641302049160003662109375
0.999653818067083310694442843669094145298004150390625
0.999653828037488256796905261580832302570343017578125
0.9996538280461171321888969032443128526210784912109375
0.999653828046176418098411886603571474552154541015625
0.9941226489001546706703038580599240958690643310546875
]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.