150 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			150 lines
		
	
	
		
			4.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| 
 | |
| #include "math_log10.h"
 | |
| 
 | |
| const math_log10_tbl_t log10_tbl[] = {
 | |
|     {0.0,     1         },
 | |
|     {0.2,     2         },
 | |
|     {0.4,     3         },
 | |
|     {0.6,     4         },
 | |
|     {0.7,     5         },
 | |
|     {0.8,     6         },
 | |
|     {0.9,     8         },
 | |
|     {1.0,     10        },
 | |
|     {1.1,     13        },
 | |
|     {1.2,     16        },
 | |
|     {1.3,     20        },
 | |
|     {1.4,     25        },
 | |
|     {1.5,     32        },
 | |
|     {1.6,     40        },
 | |
|     {1.7,     50        },
 | |
|     {1.8,     63        },
 | |
|     {1.9,     79        },
 | |
|     {2.0,     100       },
 | |
|     {2.1,     126       },
 | |
|     {2.2,     158       },
 | |
|     {2.3,     200       },
 | |
|     {2.4,     251       },
 | |
|     {2.5,     316       },
 | |
|     {2.6,     398       },
 | |
|     {2.7,     501       },
 | |
|     {2.8,     631       },
 | |
|     {2.9,     794       },
 | |
|     {3.0,     1000      },
 | |
|     {3.1,     1259      },
 | |
|     {3.2,     1585      },
 | |
|     {3.3,     1995      },
 | |
|     {3.4,     2512      },
 | |
|     {3.5,     3162      },
 | |
|     {3.6,     3981      },
 | |
|     {3.7,     5012      },
 | |
|     {3.8,     6310      },
 | |
|     {3.9,     7943      },
 | |
|     {4.0,     10000     },
 | |
|     {4.1,     12589     },
 | |
|     {4.2,     15849     },
 | |
|     {4.3,     19953     },
 | |
|     {4.4,     25119     },
 | |
|     {4.5,     31623     },
 | |
|     {4.6,     39811     },
 | |
|     {4.7,     50119     },
 | |
|     {4.8,     63096     },
 | |
|     {4.9,     79433     },
 | |
|     {5.0,     100000    },
 | |
|     {5.1,     125893    },
 | |
|     {5.2,     158489    },
 | |
|     {5.3,     199526    },
 | |
|     {5.4,     251189    },
 | |
|     {5.5,     316228    },
 | |
|     {5.6,     398107    },
 | |
|     {5.7,     501187    },
 | |
|     {5.8,     630957    },
 | |
|     {5.9,     794328    },
 | |
|     {6.0,     1000000   },
 | |
|     {6.1,     1258925   },
 | |
|     {6.2,     1584893   },
 | |
|     {6.3,     1995262   },
 | |
|     {6.4,     2511886   },
 | |
|     {6.5,     3162277   },
 | |
|     {6.6,     3981071   },
 | |
|     {6.7,     5011872   },
 | |
|     {6.8,     6309573   },
 | |
|     {6.9,     7943282   },
 | |
|     {7.0,     10000000  },
 | |
|     {7.1,     12589254  },
 | |
|     {7.2,     15848931  },
 | |
|     {7.3,     19952623  },
 | |
|     {7.4,     25118864  },
 | |
|     {7.5,     31622776  },
 | |
|     {7.6,     39810717  },
 | |
|     {7.7,     50118723  },
 | |
|     {7.8,     63095734  },
 | |
|     {7.9,     79432823  },
 | |
|     {8.0,     100000000 },
 | |
|     {8.1,     125892541 },
 | |
|     {8.2,     158489319 },
 | |
|     {8.3,     199526231 },
 | |
|     {8.4,     251188643 },
 | |
|     {8.5,     316227766 },
 | |
|     {8.6,     398107170 },
 | |
|     {8.7,     501187233 },
 | |
|     {8.8,     630957344 },
 | |
|     {8.9,     794328234 },
 | |
|     {9.0,     1000000000},
 | |
|     {9.1,     1258925411},
 | |
|     {9.2,     1584893192},
 | |
|     {9.3,     1995262314},
 | |
|     {9.4,     2511886431},
 | |
|     {9.5,     3162277660},
 | |
|     {9.6,     3981071705},
 | |
|     /* the maximum value of uint32 type is 4294967295 */
 | |
|     {9.7,     5011872336},
 | |
|     {9.8,     6309573444},
 | |
|     {9.9,     7943282347},
 | |
|     {10.0,    10000000000},
 | |
|     {11.0,    100000000000},
 | |
|     {12.0,    1000000000000},
 | |
|     {13.0,    10000000000000},
 | |
|     {14.0,    100000000000000},
 | |
|     {15.0,    1000000000000000},
 | |
|     {16.0,    10000000000000000},
 | |
|     {17.0,    100000000000000000},
 | |
|     {18.0,    1000000000000000000},
 | |
|     //{19.0,    10000000000000000000}, /* uint64_t max */
 | |
| };
 | |
| 
 | |
| float mlog10(uint64_t raw_data)
 | |
| {
 | |
|     uint32_t i;
 | |
|     if(raw_data <= log10_tbl[0].raw_data){
 | |
|         return log10_tbl[0].log10_val;
 | |
|     }
 | |
| 
 | |
|     for(i = 1; i < sizeof(log10_tbl)/sizeof(math_log10_tbl_t); i++)
 | |
|     {
 | |
|         if(raw_data == log10_tbl[i].raw_data){
 | |
|             return log10_tbl[i].log10_val;
 | |
|         }
 | |
|         else if(raw_data > log10_tbl[i-1].raw_data && \
 | |
|             raw_data < log10_tbl[i].raw_data){
 | |
|             return log10_tbl[i-1].log10_val;
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     return log10_tbl[i-1].log10_val;
 | |
| }
 | |
| 
 |