Here you can find the source of isFibonacci(long f)
public static boolean isFibonacci(long f)
//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)); } }