             let pixel = pixelY * imageWidth + pixelX
 
             if iter < maxIterations {
-                smoothedDistancesToNextIterationPerPixel[pixel] = 1.0 - min(1.0, (log(log(finalMagnitude)) - logLogBailout) / log2)
+                smoothedDistancesToNextIterationPerPixel[pixel] = 1.0 - Float(min(1.0, (log(log(finalMagnitude)) - logLogBailout) / log2))
                 histogram[iter] += 1  // no need to count histogram[max_iterations]
             }
 

    return (0.0, 0.0, 0.0)
}

func mandelbrotCalc(_ imageWidth: Int, _ imageHeight: Int, _ maxIterations: Int, _ centerX: Double, _ centerY: Double, _ height: Double, _ histogram: inout [Int], _ iterationsPerPixel: inout [Int], _ smoothedDistancesToNextIterationPerPixel: inout [Double]) {
    let width = height * (Double(imageWidth) / Double(imageHeight))

    let xLeft   = centerX - width / 2.0

}


// Compare two float values for "enough" equality.
func equalEnough(_ a: Float, _ b: Float) -> Bool {
    let absA = abs(a)
    let absB = abs(b)

    return abs(absA - absB) <= max(absA, absB) * Float.ulpOfOne
}

func gradientGetIndexOfColorAtPosition(_ gradient: Gradient, _ pos: Float) -> Int? {
    for i in 0..<gradient.colors.count {
        if equalEnough(gradient.colors[i].pos, pos) {
            return i
