import scala.math._ import scala.language.implicitConversions // BigDecimalとDoubleをアレする implicit def bd2d(bd:BigDecimal):Double = bd.doubleValue // heightとwidthをhiでびよ〜んってする def biyoon(height: Int)(width: Int)(hi: BigDecimal) = { (height * hi, width * hi) } // 元となる縦横の値を入れとく. val blogImageSize = biyoon(640)(426) _ // from - toまでstepで刻んだリスト // doubleでそのままやったら小数点以下がキモくなったので安易にBigDecimalにした def doubleList(from: BigDecimal, to: BigDecimal, step: BigDecimal) = { def join(resp:List[BigDecimal]):List[BigDecimal] = { val next = resp.last + step if(next >= to) resp else join(resp :+ next) } join(List(from)) } println("(hi, height, width)") doubleList(1.2, 1.5, 0.00001) // びよ〜ん .map( x => (x, blogImageSize(x))) // widthとheightがerr内に収まっているヤツのみ抽出 .filter{ case(hi, x) => val err = 0.01 val withinErrorMargin = (x: Double, err: Double) => math.abs(x - Math.floor(x)) < err val withinRange = withinErrorMargin(_: Double, err) withinRange(x._1) && withinRange(x._2) } // 読みやすいようにフラットにする .map{case (x, (y, z)) => (x, y, z)} .foreach(println) /* (hi, height, width) (1.490630,954.0031999999999,635.00838) (1.495320,957.0047999999999,637.00632) */