OLD | NEW |
1 /* | 1 /* |
2 ** 2013-04-17 | 2 ** 2013-04-17 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 m = -m; | 87 m = -m; |
88 if( m<0 ) return; | 88 if( m<0 ) return; |
89 }else if( m==0 && e>1000 && e<1000 ){ | 89 }else if( m==0 && e>1000 && e<1000 ){ |
90 sqlite3_result_double(context, 0.0); | 90 sqlite3_result_double(context, 0.0); |
91 return; | 91 return; |
92 } | 92 } |
93 while( (m>>32)&0xffe00000 ){ | 93 while( (m>>32)&0xffe00000 ){ |
94 m >>= 1; | 94 m >>= 1; |
95 e++; | 95 e++; |
96 } | 96 } |
97 while( ((m>>32)&0xfff00000)==0 ){ | 97 while( m!=0 && ((m>>32)&0xfff00000)==0 ){ |
98 m <<= 1; | 98 m <<= 1; |
99 e--; | 99 e--; |
100 } | 100 } |
101 e += 1075; | 101 e += 1075; |
102 if( e<0 ) e = m = 0; | 102 if( e<0 ) e = m = 0; |
103 if( e>0x7ff ) m = 0; | 103 if( e>0x7ff ) e = 0x7ff; |
104 a = m & ((((sqlite3_int64)1)<<52)-1); | 104 a = m & ((((sqlite3_int64)1)<<52)-1); |
105 a |= e<<52; | 105 a |= e<<52; |
106 if( isNeg ) a |= ((sqlite3_int64)1)<<63; | 106 if( isNeg ) a |= ((sqlite3_uint64)1)<<63; |
107 memcpy(&r, &a, sizeof(r)); | 107 memcpy(&r, &a, sizeof(r)); |
108 sqlite3_result_double(context, r); | 108 sqlite3_result_double(context, r); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 | 112 |
113 #ifdef _WIN32 | 113 #ifdef _WIN32 |
114 __declspec(dllexport) | 114 __declspec(dllexport) |
115 #endif | 115 #endif |
116 int sqlite3_ieee_init( | 116 int sqlite3_ieee_init( |
117 sqlite3 *db, | 117 sqlite3 *db, |
118 char **pzErrMsg, | 118 char **pzErrMsg, |
119 const sqlite3_api_routines *pApi | 119 const sqlite3_api_routines *pApi |
120 ){ | 120 ){ |
121 int rc = SQLITE_OK; | 121 int rc = SQLITE_OK; |
122 SQLITE_EXTENSION_INIT2(pApi); | 122 SQLITE_EXTENSION_INIT2(pApi); |
123 (void)pzErrMsg; /* Unused parameter */ | 123 (void)pzErrMsg; /* Unused parameter */ |
124 rc = sqlite3_create_function(db, "ieee754", 1, SQLITE_UTF8, 0, | 124 rc = sqlite3_create_function(db, "ieee754", 1, SQLITE_UTF8, 0, |
125 ieee754func, 0, 0); | 125 ieee754func, 0, 0); |
126 if( rc==SQLITE_OK ){ | 126 if( rc==SQLITE_OK ){ |
127 rc = sqlite3_create_function(db, "ieee754", 2, SQLITE_UTF8, 0, | 127 rc = sqlite3_create_function(db, "ieee754", 2, SQLITE_UTF8, 0, |
128 ieee754func, 0, 0); | 128 ieee754func, 0, 0); |
129 } | 129 } |
130 return rc; | 130 return rc; |
131 } | 131 } |
OLD | NEW |