Difference between revisions of "Erin's equation"
Jump to navigation
Jump to search
Giantsquid (talk | contribs) |
Giantsquid (talk | contribs) |
||
Line 12: | Line 12: | ||
==Fortran sourcecode== | ==Fortran sourcecode== | ||
+ | <syntaxhighlight lang="Fortran" line='line'> | ||
pure function erin(x) result(m) | pure function erin(x) result(m) | ||
use iso_fortran_env, only: wp => real64 | use iso_fortran_env, only: wp => real64 | ||
Line 20: | Line 21: | ||
m = t * floor(x/t) | m = t * floor(x/t) | ||
end function erin | end function erin | ||
+ | </syntaxhighlight> | ||
==Example== | ==Example== |
Latest revision as of 19:41, 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
1 pure function erin(x) result(m)
2 use iso_fortran_env, only: wp => real64
3 implicit none
4 real(wp),intent(in) :: x
5 real(wp) :: m,t
6 t = 10**floor(log10(x))
7 m = t * floor(x/t)
8 end function erin
Example
erin(9876.54321) = 9000.0