00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "orsa_secure_math.h"
00026 #include "orsa_error.h"
00027 #include "support.h"
00028
00029 #include <cmath>
00030
00031 #include <iostream>
00032
00033 using namespace std;
00034
00035 namespace orsa {
00036
00037
00038 double secure_pow(double x, double y) {
00039
00040 if (x<0.0) {
00041 if (rint(y)!=y) {
00042 ORSA_DOMAIN_ERROR("secure_pow(%g,%g) is undefined!",x,y);
00043 return 1.0;
00044 } else {
00045 return pow(x,y);
00046 }
00047 } else {
00048 return pow(x,y);
00049 }
00050 }
00051
00052
00053 double secure_log(double x) {
00054 if (x>0) {
00055 return log(x);
00056 } else {
00057 ORSA_DOMAIN_ERROR("secure_log(%g) is undefined!",x);
00058 return 1.0;
00059 }
00060 }
00061
00062
00063 double secure_log10(double x) {
00064 if (x>0) {
00065 return log10(x);
00066 } else {
00067 ORSA_DOMAIN_ERROR("secure_log10(%g) is undefined!",x);
00068 return 1.0;
00069 }
00070 }
00071
00072
00073 double secure_atan2(double x, double y) {
00074 if (x==0.0) {
00075 if (y==0.0) {
00076
00077 ORSA_DOMAIN_ERROR("secure_atan2(%g,%g) is undefined!",x,y);
00078 return 1.0;
00079 } else {
00080 return atan2(x,y);
00081 }
00082 } else {
00083 return atan2(x,y);
00084 }
00085 }
00086
00087
00088 double secure_asin(double x) {
00089 if ((x>1.0) || (x<-1.0)) {
00090
00091 ORSA_DOMAIN_ERROR("secure_asin(%g) is undefined!",x);
00092 return 1.0;
00093 } else {
00094 return asin(x);
00095 }
00096 }
00097
00098
00099 double secure_acos(double x) {
00100 if ((x>1.0) || (x<-1.0)) {
00101
00102 ORSA_DOMAIN_ERROR("secure_acos(%g) is undefined!",x);
00103 return 1.0;
00104 } else {
00105 return acos(x);
00106 }
00107 }
00108
00109
00110 double secure_sqrt(double x) {
00111 if (x<0) {
00112
00113 ORSA_DOMAIN_ERROR("secure_sqrt(%g) is undefined!",x);
00114 return sqrt(fabs(x));
00115 } else {
00116 return sqrt(x);
00117 }
00118 }
00119
00120 }