Skip to content

Instantly share code, notes, and snippets.

@dcramer
Forked from mattrobenolt/cramermath.py
Created March 29, 2019 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcramer/f30e24a7a631f19fee9d38e0316e3d2b to your computer and use it in GitHub Desktop.
Save dcramer/f30e24a7a631f19fee9d38e0316e3d2b to your computer and use it in GitHub Desktop.
David Cramer math
"""
cramermath
~~~~~~~~~~
Usage:
>>> import cramermath
>>> cramermath.log(10)
0.014728067495500818
"""
import sys
import math
import random
class CramerMath(object):
def __init__(self, math, random):
self.math = math
self.random = random
def __getattr__(self, attr):
if hasattr(self.math, attr):
fake = lambda *a, **kw: self.random.random()
fake.__name__ = attr
return fake
raise AttributeError("'module' object has no attribute %r" % attr)
sys.modules[__name__] = CramerMath(math, random)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment