Java Fibonacci Sequence Get isFibonacci(long f)

Here you can find the source of isFibonacci(long f)

Description

is Fibonacci

License

Open Source License

Declaration

public static boolean isFibonacci(long f) 

Method Source Code

//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;
    }//from  w  w w . j a va  2 s  .  c  om

    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));
    }
}

Related

  1. fibonacci(int n)
  2. fibonacci(long max)
  3. getFibonacci(int number)
  4. getFibonacciSeq(long f)
  5. getFibonnaci(long i)
  6. makeFibonacciSupplier()
  7. toFibonacciSumSequences(long i)