Difference between revisions of "Erin's equation"
Jump to navigation
Jump to search
Giantsquid (talk | contribs) (Created page with "'''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. ==Pytho...") |
Giantsquid (talk | contribs) |
||
Line 7: | Line 7: | ||
t = pow(10, floor(log10(x))) | t = pow(10, floor(log10(x))) | ||
return t * floor(x/t) | return t * floor(x/t) | ||
+ | |||
+ | ==Fortran sourcecode== | ||
+ | |||
+ | function erin(x) result(m) | ||
+ | use iso_fortran_env | ||
+ | implicit none | ||
+ | real(real64),intent(in) :: x | ||
+ | real(real64) :: m | ||
+ | real(real64) :: t | ||
+ | t = 10**floor(log10(x)) | ||
+ | m = t * floor(x/t) | ||
+ | end function erin | ||
==Example== | ==Example== |
Revision as of 19:04, 23 October 2015
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
def erin(x): from math import * t = pow(10, floor(log10(x))) return t * floor(x/t)
Fortran sourcecode
function erin(x) result(m) use iso_fortran_env implicit none real(real64),intent(in) :: x real(real64) :: m real(real64) :: t t = 10**floor(log10(x)) m = t * floor(x/t) end function erin
Example
erin(9876.54321) = 9000.0