Difference between revisions of "Erin's equation"
Jump to navigation
Jump to search
Giantsquid (talk | contribs) |
Giantsquid (talk | contribs) |
||
Line 3: | Line 3: | ||
==Python sourcecode== | ==Python sourcecode== | ||
+ | <syntaxhighlight lang="Python" line='line'> | ||
def erin(x): | def erin(x): | ||
from math import * | from math import * | ||
t = pow(10, floor(log10(x))) | t = pow(10, floor(log10(x))) | ||
return t * floor(x/t) | return t * floor(x/t) | ||
+ | </syntaxhighlight> | ||
==Fortran sourcecode== | ==Fortran sourcecode== |
Revision as of 19:40, 9 August 2019
Erin's equation is a mathematical function which computes the number that is the same order of magnitude as a given number, but with only one significant digit.
Python sourcecode
1 def erin(x):
2 from math import *
3 t = pow(10, floor(log10(x)))
4 return t * floor(x/t)
Fortran sourcecode
pure function erin(x) result(m) use iso_fortran_env, only: wp => real64 implicit none real(wp),intent(in) :: x real(wp) :: m,t t = 10**floor(log10(x)) m = t * floor(x/t) end function erin
Example
erin(9876.54321) = 9000.0