Skip to content

Instantly share code, notes, and snippets.

@SamClayton
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save SamClayton/bc5aa926050053b90133 to your computer and use it in GitHub Desktop.

Select an option

Save SamClayton/bc5aa926050053b90133 to your computer and use it in GitHub Desktop.
Calculate relative f-stops for photography
double a = 2;
double b = 16;
/*
println b**2.minus(a**2);
println b**2 - a**2;
double x = a**2;
double y = b**2;
double z = y-x;
double result = z/Math.log(2);
double newresult = ((b/a)**2)/2
*/
double x = Math.log10(a)
double y = Math.log10(b)
double result = Math.log10(b/a)/Math.log10(Math.sqrt(2))
println result
// This calculates 1 stop SLOWER
println Math.log10(b/a)
double divisor = Math.log10(Math.sqrt(2))
// divisor = 0.34657 = Math.log10(b/a)
println divisor
//println 10**divisor
// 10**divisor = b/a
// (10**divisor)a = b
println 10**divisor*a
double n = 10**divisor
println "boop"
println n*a
// This calculates 1 stop FASTER
println a/n
// This also calculates 1 stop FASTER than b above
// println b/(10**(Math.log10(Math.sqrt(2))))
println b/Math.sqrt(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment