Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import static java.lang.Math.*;

public class Main {
    public static final double GOLDEN_RATIO = (1 + sqrt(5)) / 2;

    public static boolean isFibonacci(long f) {
        return f == 0 || f == 1 || getFibonacciFast(getFibonacciSeq(f)) == f;
    }

    public static long getFibonacciFast(int n) {
        return (long) Math.floor(pow(GOLDEN_RATIO, n) / sqrt(5) + 0.5);
    }

    public static int getFibonacciSeq(long f) {
        return (int) Math.floor(Math.log(f * sqrt(5) + 0.5) / Math.log(GOLDEN_RATIO));
    }
}