Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "TradeFedNativeTestSampleLib.h"
     18 
     19 namespace TFNativeTestSampleLib {
     20 
     21 // Calculate fibonacci recursively, where 0 <= n <= 47
     22 unsigned long fibonacci_recursive(int n) {
     23     if (n == 0) {
     24         return 0;
     25     }
     26     else if (n == 1) {
     27         return 1;
     28     }
     29     else {
     30         return fibonacci_recursive(n-1) + fibonacci_recursive(n-2);
     31     }
     32 }
     33 
     34 // Calculate fibonacci iteratively, where 0 <= n <= 47
     35 unsigned long fibonacci_iterative(int n) {
     36     unsigned long n1 = 1;
     37     unsigned long n2 = 0;
     38 
     39     if (n == 0) {
     40         return 0;
     41     }
     42     else if (n == 1) {
     43         return 1;
     44     }
     45     for (int i=1; i<n; ++i) {
     46         unsigned long current = n1 + n2;
     47         n2 = n1;
     48         n1 = current;
     49     }
     50     return n1;
     51 }
     52 
     53 // Converts Celcius to Farenheit
     54 double c_to_f(double celcius) {
     55     return ((celcius * 9) / 5) + 32.0;
     56 }
     57 
     58 // Converts Farenheit to Celcius
     59 double f_to_c(double farenheit) {
     60     return ((farenheit - 32.0) * 5) / 9;
     61 }
     62 };
     63