Tim Peters <t...@python.org> added the comment:
Bad news: on Windows, exp2(x) is way worse then pow(2, x). Here I changed the loop of Mark's little driver like so: differ = really_bad = 0 worst = 0.0 for n in range(100_000): x = random.uniform(-1000.0, 999.0) + random.random() if exp2(x) != pow(2.0, x): differ += 1 exp2err = exp2_error_ulps(x) pow2err = pow2_error_ulps(x) assert abs(pow2err) < 0.52 if abs(exp2err) >= 1.0: if abs(exp2err) > abs(worst): worst = exp2err really_bad += 1 if really_bad < 25: print(f"{x.hex():21} {x:22.17f} {exp2err:.5f}, {pow2err:.5f}") print(f"{differ=:,}") print(f"{really_bad=:,}") print(f"worst exp2 ulp error {worst:.5f}") Then output from one run: 0x1.0946680d45f28p+9 530.55005041041749791 -1.04399, -0.04399 0x1.de4f9662d84f8p+9 956.62177691995657369 -1.00976, -0.00976 -0x1.60f9152be0a09p+4 -22.06081120624188330 1.02472, 0.02472 -0x1.687b056d7a81ap+8 -360.48055156937482479 1.48743, 0.48743 0x1.8e97e9d405622p+9 797.18682337057930454 1.05224, 0.05224 -0x1.2d1e3a03eda7fp+9 -602.23614548782632028 -1.21876, -0.21876 0x1.3af55e79cd45dp+8 314.95847283612766887 -1.10044, -0.10044 0x1.0e7fba610cde6p+9 540.99787533882476964 -1.39782, -0.39782 0x1.9c7d0258e460dp+9 824.97663413192060489 1.19690, 0.19690 0x1.3de5064eb1598p+9 635.78925498637818237 1.75376, -0.24624 -0x1.d5189d23da3d0p+9 -938.19229553371587826 1.07734, 0.07734 0x1.967d0857aa500p+9 812.97681709114112891 1.23630, 0.23630 -0x1.30ee89e018914p+6 -76.23294782781550794 -1.10275, -0.10275 -0x1.e35eb8936dddbp+9 -966.74000780930089149 -1.02686, -0.02686 -0x1.28d40d7693088p+6 -74.20708260795993283 1.00352, 0.00352 -0x1.e965d067d1084p+7 -244.69885563303625986 1.21136, 0.21136 -0x1.b1fbeec1c1ba3p+7 -216.99205594529948371 -1.05536, -0.05536 -0x1.543d715a5824cp+9 -680.48002175620922571 1.24955, 0.24955 0x1.526829d46c034p+9 676.81377654336984051 -1.17826, -0.17826 -0x1.bdaf1d7850c74p+6 -111.42101085656196346 1.08670, 0.08670 -0x1.48218d1605dd0p+9 -656.26211810385029821 1.06103, 0.06103 -0x1.16298bcdb9103p+9 -556.32457896744051595 -1.23732, -0.23732 0x1.39ff24b1a7573p+8 313.99665365539038930 -1.20931, -0.20931 0x1.9cdf1d0101646p+8 412.87153631481157845 -1.23481, -0.23481 differ=38,452 really_bad=7,306 worst exp2 ulp error -1.91748 So they differed in more than a third of the cases; in about a fifth of the differing cases, the exp2 error was at least 1 ulp, and nearly 2 ulp at worst; while in all the differing cases the pow(2, x) error was under 0.52 ulp. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45917> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com