View Javadoc

1   package com.dvp.tutoriel.fibonacci;
2   
3   
4   public class MaCalculette2 implements Calculette {
5   
6   	private final static double NOMBRE_OR = 1.61803398874989;
7   	private final static double RACINE_5 = 2.236067977499;
8   
9   	public Long fibonacci(Integer n) {
10  		// REGLE RG024.4
11  		if (n <= 0) {
12  			throw new IllegalArgumentException("On ne calcule que pour des nombres positifs");
13  		}
14  
15  		// REGLE RG024.1 : f(1) = 1
16  		// REGLE RG024.2 : f(2) = 1
17  		if (n == 1 || n == 2) {
18  			return 1L;
19  		}
20  
21  		final double nominateur = Math.pow(NOMBRE_OR, n);
22  
23  		final double result = nominateur / RACINE_5;
24  		return Math.round(result);
25  	}
26  
27  }