[Python-checkins] random_triangular: sqrt() is more accurate than **0.5 (#3317)

Raymond Hettinger webhook-mailer at python.org
Mon Sep 4 19:51:09 EDT 2017


https://github.com/python/cpython/commit/f5ea83f4864232fecc042ff0d1c2401807b19280
commit: f5ea83f4864232fecc042ff0d1c2401807b19280
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2017年09月04日T16:51:06-07:00
summary:
random_triangular: sqrt() is more accurate than **0.5 (#3317)
files:
M Lib/random.py
diff --git a/Lib/random.py b/Lib/random.py
index e1c2c2bbcbe..01c0c3d25fb 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -388,7 +388,7 @@ def triangular(self, low=0.0, high=1.0, mode=None):
 u = 1.0 - u
 c = 1.0 - c
 low, high = high, low
- return low + (high - low) * (u * c) ** 0.5
+ return low + (high - low) * _sqrt(u * c)
 
 ## -------------------- normal distribution --------------------
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /