📄 lookup.c
字号:
#include "lookup.h"#include <math.h>#if OPTIMIZE# define size 53#define STEP_SIZE 1#define MAX_VALUE 26//#define size (2*MAX_VALUE)/STEP_SIZE + 1//const int size = (2* MAX_VALUE) / STEP_SIZE + 1;double val[size];// Lookup-table functions for log and exp.double lookup_exp( double x ){ int i; i=(int)((x+MAX_VALUE)/STEP_SIZE); if(i>size-1) return val[size-1]; else if(i<0) return val[0]; return val[i];}double lookup_log( double x ){ int temp,min=0,max=size-1; while(1) { temp=(min+max)/2; if(temp==max || temp==min) break; if(val[temp]<=x && x <val[temp+1]) break; else if(val[temp+1]<=x) min=temp+1; else max=temp; } return temp*STEP_SIZE-MAX_VALUE;}// Initialisation function where you can set up some// look-up tables using the math.h functionsvoid lookup_init(){ int i=0; //exp = (double *) swr_malloc(sizeof(double) * size); for(;i<size;i++) val[i]=exp( (-1 * MAX_VALUE) + (i* STEP_SIZE) ); }// Clean up the tables, that is, free eventually allocated// memoryvoid lookup_exit(){ //swr_free(exp);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -