clipsruby 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clipsruby/agenda.c +1373 -0
  3. data/ext/clipsruby/agenda.h +169 -0
  4. data/ext/clipsruby/analysis.c +1142 -0
  5. data/ext/clipsruby/analysis.h +61 -0
  6. data/ext/clipsruby/argacces.c +526 -0
  7. data/ext/clipsruby/argacces.h +77 -0
  8. data/ext/clipsruby/bload.c +884 -0
  9. data/ext/clipsruby/bload.h +94 -0
  10. data/ext/clipsruby/bmathfun.c +557 -0
  11. data/ext/clipsruby/bmathfun.h +66 -0
  12. data/ext/clipsruby/bsave.c +634 -0
  13. data/ext/clipsruby/bsave.h +130 -0
  14. data/ext/clipsruby/classcom.c +976 -0
  15. data/ext/clipsruby/classcom.h +115 -0
  16. data/ext/clipsruby/classexm.c +1376 -0
  17. data/ext/clipsruby/classexm.h +97 -0
  18. data/ext/clipsruby/classfun.c +1392 -0
  19. data/ext/clipsruby/classfun.h +164 -0
  20. data/ext/clipsruby/classinf.c +1245 -0
  21. data/ext/clipsruby/classinf.h +94 -0
  22. data/ext/clipsruby/classini.c +843 -0
  23. data/ext/clipsruby/classini.h +75 -0
  24. data/ext/clipsruby/classpsr.c +957 -0
  25. data/ext/clipsruby/classpsr.h +73 -0
  26. data/ext/clipsruby/clips.h +133 -0
  27. data/ext/clipsruby/clipsruby.c +619 -0
  28. data/ext/clipsruby/clsltpsr.c +931 -0
  29. data/ext/clipsruby/clsltpsr.h +72 -0
  30. data/ext/clipsruby/commline.c +1217 -0
  31. data/ext/clipsruby/commline.h +131 -0
  32. data/ext/clipsruby/conscomp.c +1593 -0
  33. data/ext/clipsruby/conscomp.h +150 -0
  34. data/ext/clipsruby/constant.h +264 -0
  35. data/ext/clipsruby/constrct.c +1090 -0
  36. data/ext/clipsruby/constrct.h +216 -0
  37. data/ext/clipsruby/constrnt.c +554 -0
  38. data/ext/clipsruby/constrnt.h +132 -0
  39. data/ext/clipsruby/crstrtgy.c +1088 -0
  40. data/ext/clipsruby/crstrtgy.h +85 -0
  41. data/ext/clipsruby/cstrcbin.c +185 -0
  42. data/ext/clipsruby/cstrcbin.h +61 -0
  43. data/ext/clipsruby/cstrccmp.h +43 -0
  44. data/ext/clipsruby/cstrccom.c +1791 -0
  45. data/ext/clipsruby/cstrccom.h +115 -0
  46. data/ext/clipsruby/cstrcpsr.c +835 -0
  47. data/ext/clipsruby/cstrcpsr.h +97 -0
  48. data/ext/clipsruby/cstrnbin.c +282 -0
  49. data/ext/clipsruby/cstrnbin.h +55 -0
  50. data/ext/clipsruby/cstrnchk.c +826 -0
  51. data/ext/clipsruby/cstrnchk.h +91 -0
  52. data/ext/clipsruby/cstrncmp.c +238 -0
  53. data/ext/clipsruby/cstrncmp.h +57 -0
  54. data/ext/clipsruby/cstrnops.c +1176 -0
  55. data/ext/clipsruby/cstrnops.h +47 -0
  56. data/ext/clipsruby/cstrnpsr.c +1394 -0
  57. data/ext/clipsruby/cstrnpsr.h +88 -0
  58. data/ext/clipsruby/cstrnutl.c +564 -0
  59. data/ext/clipsruby/cstrnutl.h +54 -0
  60. data/ext/clipsruby/default.c +454 -0
  61. data/ext/clipsruby/default.h +57 -0
  62. data/ext/clipsruby/defins.c +971 -0
  63. data/ext/clipsruby/defins.h +127 -0
  64. data/ext/clipsruby/developr.c +677 -0
  65. data/ext/clipsruby/developr.h +69 -0
  66. data/ext/clipsruby/dffctbin.c +477 -0
  67. data/ext/clipsruby/dffctbin.h +76 -0
  68. data/ext/clipsruby/dffctbsc.c +308 -0
  69. data/ext/clipsruby/dffctbsc.h +72 -0
  70. data/ext/clipsruby/dffctcmp.c +297 -0
  71. data/ext/clipsruby/dffctcmp.h +44 -0
  72. data/ext/clipsruby/dffctdef.c +364 -0
  73. data/ext/clipsruby/dffctdef.h +104 -0
  74. data/ext/clipsruby/dffctpsr.c +179 -0
  75. data/ext/clipsruby/dffctpsr.h +49 -0
  76. data/ext/clipsruby/dffnxbin.c +520 -0
  77. data/ext/clipsruby/dffnxbin.h +67 -0
  78. data/ext/clipsruby/dffnxcmp.c +378 -0
  79. data/ext/clipsruby/dffnxcmp.h +54 -0
  80. data/ext/clipsruby/dffnxexe.c +241 -0
  81. data/ext/clipsruby/dffnxexe.h +58 -0
  82. data/ext/clipsruby/dffnxfun.c +1192 -0
  83. data/ext/clipsruby/dffnxfun.h +155 -0
  84. data/ext/clipsruby/dffnxpsr.c +514 -0
  85. data/ext/clipsruby/dffnxpsr.h +57 -0
  86. data/ext/clipsruby/dfinsbin.c +509 -0
  87. data/ext/clipsruby/dfinsbin.h +66 -0
  88. data/ext/clipsruby/dfinscmp.c +345 -0
  89. data/ext/clipsruby/dfinscmp.h +48 -0
  90. data/ext/clipsruby/drive.c +1191 -0
  91. data/ext/clipsruby/drive.h +65 -0
  92. data/ext/clipsruby/emathfun.c +1213 -0
  93. data/ext/clipsruby/emathfun.h +99 -0
  94. data/ext/clipsruby/engine.c +1568 -0
  95. data/ext/clipsruby/engine.h +203 -0
  96. data/ext/clipsruby/entities.h +276 -0
  97. data/ext/clipsruby/envrnbld.c +514 -0
  98. data/ext/clipsruby/envrnbld.h +40 -0
  99. data/ext/clipsruby/envrnmnt.c +257 -0
  100. data/ext/clipsruby/envrnmnt.h +112 -0
  101. data/ext/clipsruby/evaluatn.c +1736 -0
  102. data/ext/clipsruby/evaluatn.h +211 -0
  103. data/ext/clipsruby/expressn.c +494 -0
  104. data/ext/clipsruby/expressn.h +154 -0
  105. data/ext/clipsruby/exprnbin.c +538 -0
  106. data/ext/clipsruby/exprnbin.h +60 -0
  107. data/ext/clipsruby/exprnops.c +564 -0
  108. data/ext/clipsruby/exprnops.h +67 -0
  109. data/ext/clipsruby/exprnpsr.c +1112 -0
  110. data/ext/clipsruby/exprnpsr.h +98 -0
  111. data/ext/clipsruby/extconf.rb +2 -0
  112. data/ext/clipsruby/extnfunc.c +1015 -0
  113. data/ext/clipsruby/extnfunc.h +157 -0
  114. data/ext/clipsruby/factbin.c +447 -0
  115. data/ext/clipsruby/factbin.h +56 -0
  116. data/ext/clipsruby/factbld.c +1035 -0
  117. data/ext/clipsruby/factbld.h +63 -0
  118. data/ext/clipsruby/factcmp.c +386 -0
  119. data/ext/clipsruby/factcmp.h +46 -0
  120. data/ext/clipsruby/factcom.c +759 -0
  121. data/ext/clipsruby/factcom.h +80 -0
  122. data/ext/clipsruby/factfile.c +1761 -0
  123. data/ext/clipsruby/factfile.h +54 -0
  124. data/ext/clipsruby/factfun.c +682 -0
  125. data/ext/clipsruby/factfun.h +77 -0
  126. data/ext/clipsruby/factgen.c +1305 -0
  127. data/ext/clipsruby/factgen.h +229 -0
  128. data/ext/clipsruby/facthsh.c +438 -0
  129. data/ext/clipsruby/facthsh.h +81 -0
  130. data/ext/clipsruby/factlhs.c +250 -0
  131. data/ext/clipsruby/factlhs.h +54 -0
  132. data/ext/clipsruby/factmch.c +905 -0
  133. data/ext/clipsruby/factmch.h +68 -0
  134. data/ext/clipsruby/factmngr.c +3373 -0
  135. data/ext/clipsruby/factmngr.h +325 -0
  136. data/ext/clipsruby/factprt.c +498 -0
  137. data/ext/clipsruby/factprt.h +60 -0
  138. data/ext/clipsruby/factqpsr.c +796 -0
  139. data/ext/clipsruby/factqpsr.h +61 -0
  140. data/ext/clipsruby/factqury.c +1267 -0
  141. data/ext/clipsruby/factqury.h +112 -0
  142. data/ext/clipsruby/factrete.c +978 -0
  143. data/ext/clipsruby/factrete.h +70 -0
  144. data/ext/clipsruby/factrhs.c +667 -0
  145. data/ext/clipsruby/factrhs.h +55 -0
  146. data/ext/clipsruby/filecom.c +353 -0
  147. data/ext/clipsruby/filecom.h +137 -0
  148. data/ext/clipsruby/filertr.c +481 -0
  149. data/ext/clipsruby/filertr.h +94 -0
  150. data/ext/clipsruby/fileutil.c +1020 -0
  151. data/ext/clipsruby/fileutil.h +50 -0
  152. data/ext/clipsruby/generate.c +1079 -0
  153. data/ext/clipsruby/generate.h +57 -0
  154. data/ext/clipsruby/genrcbin.c +902 -0
  155. data/ext/clipsruby/genrcbin.h +69 -0
  156. data/ext/clipsruby/genrccmp.c +640 -0
  157. data/ext/clipsruby/genrccmp.h +59 -0
  158. data/ext/clipsruby/genrccom.c +2017 -0
  159. data/ext/clipsruby/genrccom.h +119 -0
  160. data/ext/clipsruby/genrcexe.c +737 -0
  161. data/ext/clipsruby/genrcexe.h +73 -0
  162. data/ext/clipsruby/genrcfun.c +890 -0
  163. data/ext/clipsruby/genrcfun.h +185 -0
  164. data/ext/clipsruby/genrcpsr.c +1618 -0
  165. data/ext/clipsruby/genrcpsr.h +80 -0
  166. data/ext/clipsruby/globlbin.c +458 -0
  167. data/ext/clipsruby/globlbin.h +71 -0
  168. data/ext/clipsruby/globlbsc.c +361 -0
  169. data/ext/clipsruby/globlbsc.h +83 -0
  170. data/ext/clipsruby/globlcmp.c +330 -0
  171. data/ext/clipsruby/globlcmp.h +52 -0
  172. data/ext/clipsruby/globlcom.c +289 -0
  173. data/ext/clipsruby/globlcom.h +63 -0
  174. data/ext/clipsruby/globldef.c +1087 -0
  175. data/ext/clipsruby/globldef.h +151 -0
  176. data/ext/clipsruby/globlpsr.c +530 -0
  177. data/ext/clipsruby/globlpsr.h +59 -0
  178. data/ext/clipsruby/immthpsr.c +431 -0
  179. data/ext/clipsruby/immthpsr.h +55 -0
  180. data/ext/clipsruby/incrrset.c +530 -0
  181. data/ext/clipsruby/incrrset.h +73 -0
  182. data/ext/clipsruby/inherpsr.c +850 -0
  183. data/ext/clipsruby/inherpsr.h +52 -0
  184. data/ext/clipsruby/inscom.c +2076 -0
  185. data/ext/clipsruby/inscom.h +182 -0
  186. data/ext/clipsruby/insfile.c +1764 -0
  187. data/ext/clipsruby/insfile.h +96 -0
  188. data/ext/clipsruby/insfun.c +1451 -0
  189. data/ext/clipsruby/insfun.h +134 -0
  190. data/ext/clipsruby/insmngr.c +2550 -0
  191. data/ext/clipsruby/insmngr.h +125 -0
  192. data/ext/clipsruby/insmoddp.c +1041 -0
  193. data/ext/clipsruby/insmoddp.h +91 -0
  194. data/ext/clipsruby/insmult.c +804 -0
  195. data/ext/clipsruby/insmult.h +62 -0
  196. data/ext/clipsruby/inspsr.c +602 -0
  197. data/ext/clipsruby/inspsr.h +60 -0
  198. data/ext/clipsruby/insquery.c +1278 -0
  199. data/ext/clipsruby/insquery.h +115 -0
  200. data/ext/clipsruby/insqypsr.c +729 -0
  201. data/ext/clipsruby/insqypsr.h +63 -0
  202. data/ext/clipsruby/iofun.c +2045 -0
  203. data/ext/clipsruby/iofun.h +116 -0
  204. data/ext/clipsruby/lgcldpnd.c +644 -0
  205. data/ext/clipsruby/lgcldpnd.h +75 -0
  206. data/ext/clipsruby/main.c +112 -0
  207. data/ext/clipsruby/match.h +142 -0
  208. data/ext/clipsruby/memalloc.c +481 -0
  209. data/ext/clipsruby/memalloc.h +197 -0
  210. data/ext/clipsruby/miscfun.c +1801 -0
  211. data/ext/clipsruby/miscfun.h +132 -0
  212. data/ext/clipsruby/modulbin.c +607 -0
  213. data/ext/clipsruby/modulbin.h +84 -0
  214. data/ext/clipsruby/modulbsc.c +347 -0
  215. data/ext/clipsruby/modulbsc.h +67 -0
  216. data/ext/clipsruby/modulcmp.c +499 -0
  217. data/ext/clipsruby/modulcmp.h +54 -0
  218. data/ext/clipsruby/moduldef.c +817 -0
  219. data/ext/clipsruby/moduldef.h +271 -0
  220. data/ext/clipsruby/modulpsr.c +1150 -0
  221. data/ext/clipsruby/modulpsr.h +69 -0
  222. data/ext/clipsruby/modulutl.c +1036 -0
  223. data/ext/clipsruby/modulutl.h +84 -0
  224. data/ext/clipsruby/msgcom.c +1221 -0
  225. data/ext/clipsruby/msgcom.h +125 -0
  226. data/ext/clipsruby/msgfun.c +1076 -0
  227. data/ext/clipsruby/msgfun.h +118 -0
  228. data/ext/clipsruby/msgpass.c +1441 -0
  229. data/ext/clipsruby/msgpass.h +103 -0
  230. data/ext/clipsruby/msgpsr.c +698 -0
  231. data/ext/clipsruby/msgpsr.h +73 -0
  232. data/ext/clipsruby/multifld.c +1404 -0
  233. data/ext/clipsruby/multifld.h +130 -0
  234. data/ext/clipsruby/multifun.c +2182 -0
  235. data/ext/clipsruby/multifun.h +102 -0
  236. data/ext/clipsruby/network.h +142 -0
  237. data/ext/clipsruby/objbin.c +1522 -0
  238. data/ext/clipsruby/objbin.h +79 -0
  239. data/ext/clipsruby/objcmp.c +1507 -0
  240. data/ext/clipsruby/objcmp.h +71 -0
  241. data/ext/clipsruby/object.h +260 -0
  242. data/ext/clipsruby/objrtbin.c +701 -0
  243. data/ext/clipsruby/objrtbin.h +79 -0
  244. data/ext/clipsruby/objrtbld.c +2393 -0
  245. data/ext/clipsruby/objrtbld.h +66 -0
  246. data/ext/clipsruby/objrtcmp.c +734 -0
  247. data/ext/clipsruby/objrtcmp.h +66 -0
  248. data/ext/clipsruby/objrtfnx.c +1330 -0
  249. data/ext/clipsruby/objrtfnx.h +222 -0
  250. data/ext/clipsruby/objrtgen.c +736 -0
  251. data/ext/clipsruby/objrtgen.h +63 -0
  252. data/ext/clipsruby/objrtmch.c +1524 -0
  253. data/ext/clipsruby/objrtmch.h +160 -0
  254. data/ext/clipsruby/parsefun.c +415 -0
  255. data/ext/clipsruby/parsefun.h +67 -0
  256. data/ext/clipsruby/pattern.c +1265 -0
  257. data/ext/clipsruby/pattern.h +163 -0
  258. data/ext/clipsruby/pprint.c +328 -0
  259. data/ext/clipsruby/pprint.h +79 -0
  260. data/ext/clipsruby/prccode.c +1478 -0
  261. data/ext/clipsruby/prccode.h +145 -0
  262. data/ext/clipsruby/prcdrfun.c +640 -0
  263. data/ext/clipsruby/prcdrfun.h +95 -0
  264. data/ext/clipsruby/prcdrpsr.c +1068 -0
  265. data/ext/clipsruby/prcdrpsr.h +79 -0
  266. data/ext/clipsruby/prdctfun.c +869 -0
  267. data/ext/clipsruby/prdctfun.h +77 -0
  268. data/ext/clipsruby/prntutil.c +878 -0
  269. data/ext/clipsruby/prntutil.h +125 -0
  270. data/ext/clipsruby/proflfun.c +827 -0
  271. data/ext/clipsruby/proflfun.h +118 -0
  272. data/ext/clipsruby/reorder.c +2082 -0
  273. data/ext/clipsruby/reorder.h +172 -0
  274. data/ext/clipsruby/reteutil.c +1732 -0
  275. data/ext/clipsruby/reteutil.h +111 -0
  276. data/ext/clipsruby/retract.c +710 -0
  277. data/ext/clipsruby/retract.h +74 -0
  278. data/ext/clipsruby/router.c +737 -0
  279. data/ext/clipsruby/router.h +147 -0
  280. data/ext/clipsruby/rulebin.c +1136 -0
  281. data/ext/clipsruby/rulebin.h +153 -0
  282. data/ext/clipsruby/rulebld.c +1328 -0
  283. data/ext/clipsruby/rulebld.h +62 -0
  284. data/ext/clipsruby/rulebsc.c +517 -0
  285. data/ext/clipsruby/rulebsc.h +91 -0
  286. data/ext/clipsruby/rulecmp.c +733 -0
  287. data/ext/clipsruby/rulecmp.h +63 -0
  288. data/ext/clipsruby/rulecom.c +1583 -0
  289. data/ext/clipsruby/rulecom.h +116 -0
  290. data/ext/clipsruby/rulecstr.c +892 -0
  291. data/ext/clipsruby/rulecstr.h +53 -0
  292. data/ext/clipsruby/ruledef.c +559 -0
  293. data/ext/clipsruby/ruledef.h +179 -0
  294. data/ext/clipsruby/ruledlt.c +599 -0
  295. data/ext/clipsruby/ruledlt.h +58 -0
  296. data/ext/clipsruby/rulelhs.c +1216 -0
  297. data/ext/clipsruby/rulelhs.h +52 -0
  298. data/ext/clipsruby/rulepsr.c +1073 -0
  299. data/ext/clipsruby/rulepsr.h +61 -0
  300. data/ext/clipsruby/scanner.c +856 -0
  301. data/ext/clipsruby/scanner.h +112 -0
  302. data/ext/clipsruby/setup.h +488 -0
  303. data/ext/clipsruby/sortfun.c +433 -0
  304. data/ext/clipsruby/sortfun.h +55 -0
  305. data/ext/clipsruby/strngfun.c +1173 -0
  306. data/ext/clipsruby/strngfun.h +96 -0
  307. data/ext/clipsruby/strngrtr.c +523 -0
  308. data/ext/clipsruby/strngrtr.h +97 -0
  309. data/ext/clipsruby/symblbin.c +648 -0
  310. data/ext/clipsruby/symblbin.h +64 -0
  311. data/ext/clipsruby/symblcmp.c +893 -0
  312. data/ext/clipsruby/symblcmp.h +61 -0
  313. data/ext/clipsruby/symbol.c +1961 -0
  314. data/ext/clipsruby/symbol.h +243 -0
  315. data/ext/clipsruby/sysdep.c +894 -0
  316. data/ext/clipsruby/sysdep.h +164 -0
  317. data/ext/clipsruby/textpro.c +1388 -0
  318. data/ext/clipsruby/textpro.h +77 -0
  319. data/ext/clipsruby/tmpltbin.c +609 -0
  320. data/ext/clipsruby/tmpltbin.h +108 -0
  321. data/ext/clipsruby/tmpltbsc.c +327 -0
  322. data/ext/clipsruby/tmpltbsc.h +87 -0
  323. data/ext/clipsruby/tmpltcmp.c +450 -0
  324. data/ext/clipsruby/tmpltcmp.h +57 -0
  325. data/ext/clipsruby/tmpltdef.c +584 -0
  326. data/ext/clipsruby/tmpltdef.h +155 -0
  327. data/ext/clipsruby/tmpltfun.c +2477 -0
  328. data/ext/clipsruby/tmpltfun.h +122 -0
  329. data/ext/clipsruby/tmpltlhs.c +379 -0
  330. data/ext/clipsruby/tmpltlhs.h +50 -0
  331. data/ext/clipsruby/tmpltpsr.c +819 -0
  332. data/ext/clipsruby/tmpltpsr.h +59 -0
  333. data/ext/clipsruby/tmpltrhs.c +595 -0
  334. data/ext/clipsruby/tmpltrhs.h +55 -0
  335. data/ext/clipsruby/tmpltutl.c +637 -0
  336. data/ext/clipsruby/tmpltutl.h +82 -0
  337. data/ext/clipsruby/userdata.c +156 -0
  338. data/ext/clipsruby/userdata.h +72 -0
  339. data/ext/clipsruby/userfunctions.c +70 -0
  340. data/ext/clipsruby/usrsetup.h +7 -0
  341. data/ext/clipsruby/utility.c +1594 -0
  342. data/ext/clipsruby/utility.h +250 -0
  343. data/ext/clipsruby/watch.c +865 -0
  344. data/ext/clipsruby/watch.h +124 -0
  345. data/lib/clipsruby.rb +1 -0
  346. metadata +388 -0
@@ -0,0 +1,1213 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 05/01/20 */
5
+ /* */
6
+ /* EXTENDED MATH FUNCTIONS MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: Contains the code for numerous extended math */
11
+ /* functions including cos, sin, tan, sec, csc, cot, acos, */
12
+ /* asin, atan, atan2, asec, acsc, acot, cosh, sinh, tanh, */
13
+ /* sech, csch, coth, acosh, asinh, atanh, asech, acsch, */
14
+ /* acoth, mod, exp, log, log10, sqrt, pi, deg-rad, */
15
+ /* rad-deg, deg-grad, grad-deg, **, and round. */
16
+ /* */
17
+ /* Principal Programmer(s): */
18
+ /* Brian L. Dantes */
19
+ /* */
20
+ /* Contributing Programmer(s): */
21
+ /* Gary D. Riley */
22
+ /* */
23
+ /* Revision History: */
24
+ /* */
25
+ /* 6.30: Removed conditional code for unsupported */
26
+ /* compilers/operating systems (IBM_MCW and */
27
+ /* MAC_MCW). */
28
+ /* */
29
+ /* Support for long long integers. */
30
+ /* */
31
+ /* Renamed EX_MATH compiler flag to */
32
+ /* EXTENDED_MATH_FUNCTIONS. */
33
+ /* */
34
+ /* Added const qualifiers to remove C++ */
35
+ /* deprecation warnings. */
36
+ /* */
37
+ /* 6.31: Fix for overflow error in div function. */
38
+ /* */
39
+ /* 6.40: Added Env prefix to GetEvaluationError and */
40
+ /* SetEvaluationError functions. */
41
+ /* */
42
+ /* Added Env prefix to GetHaltExecution and */
43
+ /* SetHaltExecution functions. */
44
+ /* */
45
+ /* Added support for booleans with <stdbool.h>. */
46
+ /* */
47
+ /* Removed use of void pointers for specific */
48
+ /* data structures. */
49
+ /* */
50
+ /* UDF redesign. */
51
+ /* */
52
+ /* Added error codes for get-error and */
53
+ /* clear-error functions. */
54
+ /* */
55
+ /* Added atan2 function. */
56
+ /* */
57
+ /* Round function rounds away from zero if its */
58
+ /* argument is halfway between two integers. */
59
+ /* */
60
+ /*************************************************************/
61
+
62
+ #include "setup.h"
63
+ #include "argacces.h"
64
+ #include "envrnmnt.h"
65
+ #include "extnfunc.h"
66
+ #include "miscfun.h"
67
+ #include "prntutil.h"
68
+ #include "router.h"
69
+
70
+ #include "emathfun.h"
71
+
72
+ #if EXTENDED_MATH_FUNCTIONS
73
+
74
+ #include <math.h>
75
+
76
+ /***************/
77
+ /* DEFINITIONS */
78
+ /***************/
79
+
80
+ #ifndef PI
81
+ #define PI 3.14159265358979323846
82
+ #endif
83
+
84
+ #ifndef PID2
85
+ #define PID2 1.57079632679489661923 /* PI divided by 2 */
86
+ #endif
87
+
88
+ #define SMALLEST_ALLOWED_NUMBER 1e-15
89
+ #define dtrunc(x) (((x) < 0.0) ? ceil(x) : floor(x))
90
+
91
+ /***************************************/
92
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
93
+ /***************************************/
94
+
95
+ static bool SingleNumberCheck(UDFContext *,UDFValue *);
96
+ static bool TestProximity(double,double);
97
+ static void DomainErrorMessage(UDFContext *,UDFValue *);
98
+ static void ArgumentOverflowErrorMessage(UDFContext *,UDFValue *);
99
+ static void SingularityErrorMessage(UDFContext *,UDFValue *);
100
+ static double genacosh(double);
101
+ static double genasinh(double);
102
+ static double genatanh(double);
103
+ static double genasech(double);
104
+ static double genacsch(double);
105
+ static double genacoth(double);
106
+
107
+ /************************************************/
108
+ /* ExtendedMathFunctionDefinitions: Initializes */
109
+ /* the extended math functions. */
110
+ /************************************************/
111
+ void ExtendedMathFunctionDefinitions(
112
+ Environment *theEnv)
113
+ {
114
+ #if ! RUN_TIME
115
+ AddUDF(theEnv,"cos","d",1,1,"ld",CosFunction,"CosFunction",NULL);
116
+ AddUDF(theEnv,"sin","d",1,1,"ld",SinFunction,"SinFunction",NULL);
117
+ AddUDF(theEnv,"tan","d",1,1,"ld",TanFunction,"TanFunction",NULL);
118
+ AddUDF(theEnv,"sec","d",1,1,"ld",SecFunction,"SecFunction",NULL);
119
+ AddUDF(theEnv,"csc","d",1,1,"ld",CscFunction,"CscFunction",NULL);
120
+ AddUDF(theEnv,"cot","d",1,1,"ld",CotFunction,"CotFunction",NULL);
121
+ AddUDF(theEnv,"acos","d",1,1,"ld",AcosFunction,"AcosFunction",NULL);
122
+ AddUDF(theEnv,"asin","d",1,1,"ld",AsinFunction,"AsinFunction",NULL);
123
+ AddUDF(theEnv,"atan","d",1,1,"ld",AtanFunction,"AtanFunction",NULL);
124
+ AddUDF(theEnv,"atan2","d",2,2,"ld",Atan2Function,"Atan2Function",NULL);
125
+ AddUDF(theEnv,"asec","d",1,1,"ld",AsecFunction,"AsecFunction",NULL);
126
+ AddUDF(theEnv,"acsc","d",1,1,"ld",AcscFunction,"AcscFunction",NULL);
127
+ AddUDF(theEnv,"acot","d",1,1,"ld",AcotFunction,"AcotFunction",NULL);
128
+ AddUDF(theEnv,"cosh","d",1,1,"ld",CoshFunction,"CoshFunction",NULL);
129
+ AddUDF(theEnv,"sinh","d",1,1,"ld",SinhFunction,"SinhFunction",NULL);
130
+ AddUDF(theEnv,"tanh","d",1,1,"ld",TanhFunction,"TanhFunction",NULL);
131
+ AddUDF(theEnv,"sech","d",1,1,"ld",SechFunction,"SechFunction",NULL);
132
+ AddUDF(theEnv,"csch","d",1,1,"ld",CschFunction,"CschFunction",NULL);
133
+ AddUDF(theEnv,"coth","d",1,1,"ld",CothFunction,"CothFunction",NULL);
134
+ AddUDF(theEnv,"acosh","d",1,1,"ld",AcoshFunction,"AcoshFunction",NULL);
135
+ AddUDF(theEnv,"asinh","d",1,1,"ld",AsinhFunction,"AsinhFunction",NULL);
136
+ AddUDF(theEnv,"atanh","d",1,1,"ld",AtanhFunction,"AtanhFunction",NULL);
137
+ AddUDF(theEnv,"asech","d",1,1,"ld",AsechFunction,"AsechFunction",NULL);
138
+ AddUDF(theEnv,"acsch","d",1,1,"ld",AcschFunction,"AcschFunction",NULL);
139
+ AddUDF(theEnv,"acoth","d",1,1,"ld",AcothFunction,"AcothFunction",NULL);
140
+
141
+ AddUDF(theEnv,"mod","ld",2,2,"ld",ModFunction,"ModFunction",NULL);
142
+ AddUDF(theEnv,"exp","d", 1,1,"ld",ExpFunction,"ExpFunction",NULL);
143
+ AddUDF(theEnv,"log","d",1,1,"ld",LogFunction,"LogFunction",NULL);
144
+ AddUDF(theEnv,"log10","d",1,1,"ld",Log10Function,"Log10Function",NULL);
145
+ AddUDF(theEnv,"sqrt","d",1,1,"ld",SqrtFunction,"SqrtFunction",NULL);
146
+ AddUDF(theEnv,"pi","d",0,0,NULL,PiFunction, "PiFunction",NULL);
147
+ AddUDF(theEnv,"deg-rad","d",1,1,"ld",DegRadFunction, "DegRadFunction",NULL);
148
+ AddUDF(theEnv,"rad-deg","d",1,1,"ld",RadDegFunction, "RadDegFunction",NULL);
149
+ AddUDF(theEnv,"deg-grad","d",1,1,"ld",DegGradFunction,"DegGradFunction",NULL);
150
+ AddUDF(theEnv,"grad-deg","d",1,1,"ld",GradDegFunction,"GradDegFunction",NULL);
151
+ AddUDF(theEnv,"**","d",2,2,"ld",PowFunction,"PowFunction",NULL);
152
+ AddUDF(theEnv,"round","l", 1,1,"ld",RoundFunction,"RoundFunction",NULL);
153
+ #else
154
+ #if MAC_XCD
155
+ #pragma unused(theEnv)
156
+ #endif
157
+ #endif
158
+ }
159
+
160
+ /************************************************************/
161
+ /* SingleNumberCheck: Retrieves the numeric argument for */
162
+ /* extended math functions which expect a single floating */
163
+ /* point argument. */
164
+ /************************************************************/
165
+ static bool SingleNumberCheck(
166
+ UDFContext *context,
167
+ UDFValue *returnValue)
168
+ {
169
+ /*======================================*/
170
+ /* Check that the argument is a number. */
171
+ /*======================================*/
172
+
173
+ if (! UDFNthArgument(context,1,NUMBER_BITS,returnValue))
174
+ {
175
+ returnValue->floatValue = CreateFloat(context->environment,0.0);
176
+ return false;
177
+ }
178
+
179
+ return true;
180
+ }
181
+
182
+ /**************************************************************/
183
+ /* TestProximity: Returns true if the specified number falls */
184
+ /* within the specified range, otherwise false is returned. */
185
+ /**************************************************************/
186
+ static bool TestProximity(
187
+ double theNumber,
188
+ double range)
189
+ {
190
+ if ((theNumber >= (- range)) && (theNumber <= range)) return true;
191
+ else return false;
192
+ }
193
+
194
+ /********************************************************/
195
+ /* DomainErrorMessage: Generic error message used when */
196
+ /* a domain error is detected during a call to one of */
197
+ /* the extended math functions. */
198
+ /********************************************************/
199
+ static void DomainErrorMessage(
200
+ UDFContext *context,
201
+ UDFValue *returnValue)
202
+ {
203
+ Environment *theEnv = context->environment;
204
+
205
+ SetErrorValue(theEnv,&CreateSymbol(theEnv,"DOMAIN_ERROR")->header);
206
+ PrintErrorID(theEnv,"EMATHFUN",1,false);
207
+ WriteString(theEnv,STDERR,"Domain error for '");
208
+ WriteString(theEnv,STDERR,UDFContextFunctionName(context));
209
+ WriteString(theEnv,STDERR,"' function.\n");
210
+ SetHaltExecution(theEnv,true);
211
+ SetEvaluationError(theEnv,true);
212
+ returnValue->floatValue = CreateFloat(theEnv,0.0);
213
+ }
214
+
215
+ /************************************************************/
216
+ /* ArgumentOverflowErrorMessage: Generic error message used */
217
+ /* when an argument overflow is detected during a call to */
218
+ /* one of the extended math functions. */
219
+ /************************************************************/
220
+ static void ArgumentOverflowErrorMessage(
221
+ UDFContext *context,
222
+ UDFValue *returnValue)
223
+ {
224
+ Environment *theEnv = context->environment;
225
+
226
+ SetErrorValue(theEnv,&CreateSymbol(theEnv,"ARGUMENT_OVERFLOW")->header);
227
+ PrintErrorID(theEnv,"EMATHFUN",2,false);
228
+ WriteString(theEnv,STDERR,"Argument overflow for '");
229
+ WriteString(theEnv,STDERR,UDFContextFunctionName(context));
230
+ WriteString(theEnv,STDERR,"' function.\n");
231
+ SetHaltExecution(theEnv,true);
232
+ SetEvaluationError(theEnv,true);
233
+ returnValue->floatValue = CreateFloat(theEnv,0.0);
234
+ }
235
+
236
+ /************************************************************/
237
+ /* SingularityErrorMessage: Generic error message used when */
238
+ /* a singularity is detected during a call to one of the */
239
+ /* extended math functions. */
240
+ /************************************************************/
241
+ static void SingularityErrorMessage(
242
+ UDFContext *context,
243
+ UDFValue *returnValue)
244
+ {
245
+ Environment *theEnv = context->environment;
246
+
247
+ SetErrorValue(theEnv,&CreateSymbol(theEnv,"SINGULARITY_AT_ASYMPTOTE")->header);
248
+ PrintErrorID(theEnv,"EMATHFUN",3,false);
249
+ WriteString(theEnv,STDERR,"Singularity at asymptote in '");
250
+ WriteString(theEnv,STDERR,UDFContextFunctionName(context));
251
+ WriteString(theEnv,STDERR,"' function.\n");
252
+ SetHaltExecution(theEnv,true);
253
+ SetEvaluationError(theEnv,true);
254
+ returnValue->floatValue = CreateFloat(theEnv,0.0);
255
+ }
256
+
257
+ /*************************************/
258
+ /* CosFunction: H/L access routine */
259
+ /* for the cos function. */
260
+ /*************************************/
261
+ void CosFunction(
262
+ Environment *theEnv,
263
+ UDFContext *context,
264
+ UDFValue *returnValue)
265
+ {
266
+ if (! SingleNumberCheck(context,returnValue))
267
+ { return; }
268
+
269
+ returnValue->floatValue = CreateFloat(theEnv,cos(CVCoerceToFloat(returnValue)));
270
+ }
271
+
272
+ /*************************************/
273
+ /* SinFunction: H/L access routine */
274
+ /* for the sin function. */
275
+ /*************************************/
276
+ void SinFunction(
277
+ Environment *theEnv,
278
+ UDFContext *context,
279
+ UDFValue *returnValue)
280
+ {
281
+ if (! SingleNumberCheck(context,returnValue))
282
+ { return; }
283
+
284
+ returnValue->floatValue = CreateFloat(theEnv,sin(CVCoerceToFloat(returnValue)));
285
+ }
286
+
287
+ /*************************************/
288
+ /* TanFunction: H/L access routine */
289
+ /* for the tan function. */
290
+ /*************************************/
291
+ void TanFunction(
292
+ Environment *theEnv,
293
+ UDFContext *context,
294
+ UDFValue *returnValue)
295
+ {
296
+ double tv;
297
+
298
+ ClearErrorValue(theEnv);
299
+
300
+ if (! SingleNumberCheck(context,returnValue))
301
+ { return; }
302
+
303
+ tv = cos(CVCoerceToFloat(returnValue));
304
+ if ((tv < SMALLEST_ALLOWED_NUMBER) && (tv > -SMALLEST_ALLOWED_NUMBER))
305
+ {
306
+ SingularityErrorMessage(context,returnValue);
307
+ return;
308
+ }
309
+
310
+ returnValue->floatValue = CreateFloat(theEnv,sin(CVCoerceToFloat(returnValue)) / tv);
311
+ }
312
+
313
+ /*************************************/
314
+ /* SecFunction: H/L access routine */
315
+ /* for the sec function. */
316
+ /*************************************/
317
+ void SecFunction(
318
+ Environment *theEnv,
319
+ UDFContext *context,
320
+ UDFValue *returnValue)
321
+ {
322
+ double tv;
323
+
324
+ ClearErrorValue(theEnv);
325
+
326
+ if (! SingleNumberCheck(context,returnValue))
327
+ { return; }
328
+
329
+ tv = cos(CVCoerceToFloat(returnValue));
330
+ if ((tv < SMALLEST_ALLOWED_NUMBER) && (tv > -SMALLEST_ALLOWED_NUMBER))
331
+ {
332
+ SingularityErrorMessage(context,returnValue);
333
+ return;
334
+ }
335
+
336
+ returnValue->floatValue = CreateFloat(theEnv,1.0 / tv);
337
+ }
338
+
339
+ /*************************************/
340
+ /* CscFunction: H/L access routine */
341
+ /* for the csc function. */
342
+ /*************************************/
343
+ void CscFunction(
344
+ Environment *theEnv,
345
+ UDFContext *context,
346
+ UDFValue *returnValue)
347
+ {
348
+ double tv;
349
+
350
+ ClearErrorValue(theEnv);
351
+
352
+ if (! SingleNumberCheck(context,returnValue))
353
+ { return; }
354
+
355
+ tv = sin(CVCoerceToFloat(returnValue));
356
+ if ((tv < SMALLEST_ALLOWED_NUMBER) && (tv > -SMALLEST_ALLOWED_NUMBER))
357
+ {
358
+ SingularityErrorMessage(context,returnValue);
359
+ return;
360
+ }
361
+
362
+ returnValue->floatValue = CreateFloat(theEnv,1.0 / tv);
363
+ }
364
+
365
+ /*************************************/
366
+ /* CotFunction: H/L access routine */
367
+ /* for the cot function. */
368
+ /*************************************/
369
+ void CotFunction(
370
+ Environment *theEnv,
371
+ UDFContext *context,
372
+ UDFValue *returnValue)
373
+ {
374
+ double tv;
375
+
376
+ ClearErrorValue(theEnv);
377
+
378
+ if (! SingleNumberCheck(context,returnValue))
379
+ { return; }
380
+
381
+ tv = sin(CVCoerceToFloat(returnValue));
382
+ if ((tv < SMALLEST_ALLOWED_NUMBER) && (tv > -SMALLEST_ALLOWED_NUMBER))
383
+ {
384
+ SingularityErrorMessage(context,returnValue);
385
+ return;
386
+ }
387
+
388
+ returnValue->floatValue = CreateFloat(theEnv,cos(CVCoerceToFloat(returnValue)) / tv);
389
+ }
390
+
391
+ /**************************************/
392
+ /* AcosFunction: H/L access routine */
393
+ /* for the acos function. */
394
+ /**************************************/
395
+ void AcosFunction(
396
+ Environment *theEnv,
397
+ UDFContext *context,
398
+ UDFValue *returnValue)
399
+ {
400
+ double num;
401
+
402
+ ClearErrorValue(theEnv);
403
+
404
+ if (! SingleNumberCheck(context,returnValue))
405
+ { return; }
406
+
407
+ num = CVCoerceToFloat(returnValue);
408
+
409
+ if ((num > 1.0) || (num < -1.0))
410
+ {
411
+ DomainErrorMessage(context,returnValue);
412
+ return;
413
+ }
414
+
415
+ returnValue->floatValue = CreateFloat(theEnv,acos(num));
416
+ }
417
+
418
+ /**************************************/
419
+ /* AsinFunction: H/L access routine */
420
+ /* for the asin function. */
421
+ /**************************************/
422
+ void AsinFunction(
423
+ Environment *theEnv,
424
+ UDFContext *context,
425
+ UDFValue *returnValue)
426
+ {
427
+ double num;
428
+
429
+ ClearErrorValue(theEnv);
430
+
431
+ if (! SingleNumberCheck(context,returnValue))
432
+ { return; }
433
+
434
+ num = CVCoerceToFloat(returnValue);
435
+ if ((num > 1.0) || (num < -1.0))
436
+ {
437
+ DomainErrorMessage(context,returnValue);
438
+ return;
439
+ }
440
+
441
+ returnValue->floatValue = CreateFloat(theEnv,asin(num));
442
+ }
443
+
444
+ /**************************************/
445
+ /* AtanFunction: H/L access routine */
446
+ /* for the atan function. */
447
+ /**************************************/
448
+ void AtanFunction(
449
+ Environment *theEnv,
450
+ UDFContext *context,
451
+ UDFValue *returnValue)
452
+ {
453
+ if (! SingleNumberCheck(context,returnValue))
454
+ { return; }
455
+
456
+ returnValue->floatValue = CreateFloat(theEnv,atan(CVCoerceToFloat(returnValue)));
457
+ }
458
+
459
+ /***************************************/
460
+ /* Atan2Function: H/L access routine */
461
+ /* for the atan function. */
462
+ /***************************************/
463
+ void Atan2Function(
464
+ Environment *theEnv,
465
+ UDFContext *context,
466
+ UDFValue *returnValue)
467
+ {
468
+ UDFValue value1, value2;
469
+ double x, y;
470
+
471
+ ClearErrorValue(theEnv);
472
+
473
+ /*==================================*/
474
+ /* Check for two numeric arguments. */
475
+ /*==================================*/
476
+
477
+ if (! UDFNthArgument(context,1,NUMBER_BITS,&value1))
478
+ { return; }
479
+
480
+ if (! UDFNthArgument(context,2,NUMBER_BITS,&value2))
481
+ { return; }
482
+
483
+ y = CVCoerceToFloat(&value1);
484
+ x = CVCoerceToFloat(&value2);
485
+
486
+ if ((x == 0.0) && (y == 0.0))
487
+ {
488
+ DomainErrorMessage(context,returnValue);
489
+ return;
490
+ }
491
+
492
+ /*============================*/
493
+ /* Compute and set the value. */
494
+ /*============================*/
495
+
496
+ returnValue->floatValue = CreateFloat(theEnv,atan2(y,x));
497
+ }
498
+
499
+ /**************************************/
500
+ /* AsecFunction: H/L access routine */
501
+ /* for the asec function. */
502
+ /**************************************/
503
+ void AsecFunction(
504
+ Environment *theEnv,
505
+ UDFContext *context,
506
+ UDFValue *returnValue)
507
+ {
508
+ double num;
509
+
510
+ ClearErrorValue(theEnv);
511
+
512
+ if (! SingleNumberCheck(context,returnValue))
513
+ { return; }
514
+
515
+ num = CVCoerceToFloat(returnValue);
516
+ if ((num < 1.0) && (num > -1.0))
517
+ {
518
+ DomainErrorMessage(context,returnValue);
519
+ return;
520
+ }
521
+
522
+ num = 1.0 / num;
523
+ returnValue->floatValue = CreateFloat(theEnv,acos(num));
524
+ }
525
+
526
+ /**************************************/
527
+ /* AcscFunction: H/L access routine */
528
+ /* for the acsc function. */
529
+ /**************************************/
530
+ void AcscFunction(
531
+ Environment *theEnv,
532
+ UDFContext *context,
533
+ UDFValue *returnValue)
534
+ {
535
+ double num;
536
+
537
+ ClearErrorValue(theEnv);
538
+
539
+ if (! SingleNumberCheck(context,returnValue))
540
+ { return; }
541
+
542
+ num = CVCoerceToFloat(returnValue);
543
+ if ((num < 1.0) && (num > -1.0))
544
+ {
545
+ DomainErrorMessage(context,returnValue);
546
+ return;
547
+ }
548
+
549
+ num = 1.0 / num;
550
+ returnValue->floatValue = CreateFloat(theEnv,asin(num));
551
+ }
552
+
553
+ /**************************************/
554
+ /* AcotFunction: H/L access routine */
555
+ /* for the acot function. */
556
+ /**************************************/
557
+ void AcotFunction(
558
+ Environment *theEnv,
559
+ UDFContext *context,
560
+ UDFValue *returnValue)
561
+ {
562
+ double num;
563
+
564
+ if (! SingleNumberCheck(context,returnValue))
565
+ { return; }
566
+
567
+ num = CVCoerceToFloat(returnValue);
568
+ if (TestProximity(num,1e-25) == true)
569
+ {
570
+ returnValue->floatValue = CreateFloat(theEnv,PID2);
571
+ return;
572
+ }
573
+
574
+ num = 1.0 / num;
575
+ returnValue->floatValue = CreateFloat(theEnv,atan(num));
576
+ }
577
+
578
+ /**************************************/
579
+ /* CoshFunction: H/L access routine */
580
+ /* for the cosh function. */
581
+ /**************************************/
582
+ void CoshFunction(
583
+ Environment *theEnv,
584
+ UDFContext *context,
585
+ UDFValue *returnValue)
586
+ {
587
+ if (! SingleNumberCheck(context,returnValue))
588
+ { return; }
589
+
590
+ returnValue->floatValue = CreateFloat(theEnv,cosh(CVCoerceToFloat(returnValue)));
591
+ }
592
+
593
+ /**************************************/
594
+ /* SinhFunction: H/L access routine */
595
+ /* for the sinh function. */
596
+ /**************************************/
597
+ void SinhFunction(
598
+ Environment *theEnv,
599
+ UDFContext *context,
600
+ UDFValue *returnValue)
601
+ {
602
+ if (! SingleNumberCheck(context,returnValue))
603
+ { return; }
604
+
605
+ returnValue->floatValue = CreateFloat(theEnv,sinh(CVCoerceToFloat(returnValue)));
606
+ }
607
+
608
+ /**************************************/
609
+ /* TanhFunction: H/L access routine */
610
+ /* for the tanh function. */
611
+ /**************************************/
612
+ void TanhFunction(
613
+ Environment *theEnv,
614
+ UDFContext *context,
615
+ UDFValue *returnValue)
616
+ {
617
+ if (! SingleNumberCheck(context,returnValue))
618
+ { return; }
619
+
620
+ returnValue->floatValue = CreateFloat(theEnv,tanh(CVCoerceToFloat(returnValue)));
621
+ }
622
+
623
+ /**************************************/
624
+ /* SechFunction: H/L access routine */
625
+ /* for the sech function. */
626
+ /**************************************/
627
+ void SechFunction(
628
+ Environment *theEnv,
629
+ UDFContext *context,
630
+ UDFValue *returnValue)
631
+ {
632
+ if (! SingleNumberCheck(context,returnValue))
633
+ { return; }
634
+
635
+ returnValue->floatValue = CreateFloat(theEnv,1.0 / cosh(CVCoerceToFloat(returnValue)));
636
+ }
637
+
638
+ /**************************************/
639
+ /* CschFunction: H/L access routine */
640
+ /* for the csch function. */
641
+ /**************************************/
642
+ void CschFunction(
643
+ Environment *theEnv,
644
+ UDFContext *context,
645
+ UDFValue *returnValue)
646
+ {
647
+ double num;
648
+
649
+ ClearErrorValue(theEnv);
650
+
651
+ if (! SingleNumberCheck(context,returnValue))
652
+ { return; }
653
+
654
+ num = CVCoerceToFloat(returnValue);
655
+ if (num == 0.0)
656
+ {
657
+ SingularityErrorMessage(context,returnValue);
658
+ return;
659
+ }
660
+ else if (TestProximity(num,1e-25) == true)
661
+ {
662
+ ArgumentOverflowErrorMessage(context,returnValue);
663
+ return;
664
+ }
665
+
666
+ returnValue->floatValue = CreateFloat(theEnv,1.0 / sinh(num));
667
+ }
668
+
669
+ /**************************************/
670
+ /* CothFunction: H/L access routine */
671
+ /* for the coth function. */
672
+ /**************************************/
673
+ void CothFunction(
674
+ Environment *theEnv,
675
+ UDFContext *context,
676
+ UDFValue *returnValue)
677
+ {
678
+ double num;
679
+
680
+ ClearErrorValue(theEnv);
681
+
682
+ if (! SingleNumberCheck(context,returnValue))
683
+ { return; }
684
+
685
+ num = CVCoerceToFloat(returnValue);
686
+ if (num == 0.0)
687
+ {
688
+ SingularityErrorMessage(context,returnValue);
689
+ return;
690
+ }
691
+ else if (TestProximity(num,1e-25) == true)
692
+ {
693
+ ArgumentOverflowErrorMessage(context,returnValue);
694
+ return;
695
+ }
696
+
697
+ returnValue->floatValue = CreateFloat(theEnv,1.0 / tanh(num));
698
+ }
699
+
700
+ /***************************************/
701
+ /* AcoshFunction: H/L access routine */
702
+ /* for the acosh function. */
703
+ /***************************************/
704
+ void AcoshFunction(
705
+ Environment *theEnv,
706
+ UDFContext *context,
707
+ UDFValue *returnValue)
708
+ {
709
+ double num;
710
+
711
+ ClearErrorValue(theEnv);
712
+
713
+ if (! SingleNumberCheck(context,returnValue))
714
+ { return; }
715
+
716
+ num = CVCoerceToFloat(returnValue);
717
+ if (num < 1.0)
718
+ {
719
+ DomainErrorMessage(context,returnValue);
720
+ return;
721
+ }
722
+
723
+ returnValue->floatValue = CreateFloat(theEnv,genacosh(num));
724
+ }
725
+
726
+ /***************************************/
727
+ /* AsinhFunction: H/L access routine */
728
+ /* for the asinh function. */
729
+ /***************************************/
730
+ void AsinhFunction(
731
+ Environment *theEnv,
732
+ UDFContext *context,
733
+ UDFValue *returnValue)
734
+ {
735
+ if (! SingleNumberCheck(context,returnValue))
736
+ { return; }
737
+
738
+ returnValue->floatValue = CreateFloat(theEnv,genasinh(CVCoerceToFloat(returnValue)));
739
+ }
740
+
741
+ /***************************************/
742
+ /* AtanhFunction: H/L access routine */
743
+ /* for the atanh function. */
744
+ /***************************************/
745
+ void AtanhFunction(
746
+ Environment *theEnv,
747
+ UDFContext *context,
748
+ UDFValue *returnValue)
749
+ {
750
+ double num;
751
+
752
+ ClearErrorValue(theEnv);
753
+
754
+ if (! SingleNumberCheck(context,returnValue))
755
+ { return; }
756
+
757
+ num = CVCoerceToFloat(returnValue);
758
+ if ((num >= 1.0) || (num <= -1.0))
759
+ {
760
+ DomainErrorMessage(context,returnValue);
761
+ return;
762
+ }
763
+
764
+ returnValue->floatValue = CreateFloat(theEnv,genatanh(num));
765
+ }
766
+
767
+ /***************************************/
768
+ /* AsechFunction: H/L access routine */
769
+ /* for the asech function. */
770
+ /***************************************/
771
+ void AsechFunction(
772
+ Environment *theEnv,
773
+ UDFContext *context,
774
+ UDFValue *returnValue)
775
+ {
776
+ double num;
777
+
778
+ ClearErrorValue(theEnv);
779
+
780
+ if (! SingleNumberCheck(context,returnValue))
781
+ { return; }
782
+
783
+ num = CVCoerceToFloat(returnValue);
784
+ if ((num > 1.0) || (num <= 0.0))
785
+ {
786
+ DomainErrorMessage(context,returnValue);
787
+ return;
788
+ }
789
+
790
+ returnValue->floatValue = CreateFloat(theEnv,genasech(num));
791
+ }
792
+
793
+ /***************************************/
794
+ /* AcschFunction: H/L access routine */
795
+ /* for the acsch function. */
796
+ /***************************************/
797
+ void AcschFunction(
798
+ Environment *theEnv,
799
+ UDFContext *context,
800
+ UDFValue *returnValue)
801
+ {
802
+ double num;
803
+
804
+ ClearErrorValue(theEnv);
805
+
806
+ if (! SingleNumberCheck(context,returnValue))
807
+ { return; }
808
+
809
+ num = CVCoerceToFloat(returnValue);
810
+ if (num == 0.0)
811
+ {
812
+ DomainErrorMessage(context,returnValue);
813
+ return;
814
+ }
815
+
816
+ returnValue->floatValue = CreateFloat(theEnv,genacsch(num));
817
+ }
818
+
819
+ /***************************************/
820
+ /* AcothFunction: H/L access routine */
821
+ /* for the acoth function. */
822
+ /***************************************/
823
+ void AcothFunction(
824
+ Environment *theEnv,
825
+ UDFContext *context,
826
+ UDFValue *returnValue)
827
+ {
828
+ double num;
829
+
830
+ ClearErrorValue(theEnv);
831
+
832
+ if (! SingleNumberCheck(context,returnValue))
833
+ { return; }
834
+
835
+ num = CVCoerceToFloat(returnValue);
836
+ if ((num <= 1.0) && (num >= -1.0))
837
+ {
838
+ DomainErrorMessage(context,returnValue);
839
+ return;
840
+ }
841
+
842
+ returnValue->floatValue = CreateFloat(theEnv,genacoth(num));
843
+ }
844
+
845
+ /*************************************/
846
+ /* ExpFunction: H/L access routine */
847
+ /* for the exp function. */
848
+ /*************************************/
849
+ void ExpFunction(
850
+ Environment *theEnv,
851
+ UDFContext *context,
852
+ UDFValue *returnValue)
853
+ {
854
+ if (! SingleNumberCheck(context,returnValue))
855
+ { return; }
856
+
857
+ returnValue->floatValue = CreateFloat(theEnv,exp(CVCoerceToFloat(returnValue)));
858
+ }
859
+
860
+ /*************************************/
861
+ /* LogFunction: H/L access routine */
862
+ /* for the log function. */
863
+ /*************************************/
864
+ void LogFunction(
865
+ Environment *theEnv,
866
+ UDFContext *context,
867
+ UDFValue *returnValue)
868
+ {
869
+ double num;
870
+
871
+ ClearErrorValue(theEnv);
872
+
873
+ if (! SingleNumberCheck(context,returnValue))
874
+ { return; }
875
+
876
+ num = CVCoerceToFloat(returnValue);
877
+ if (num < 0.0)
878
+ {
879
+ DomainErrorMessage(context,returnValue);
880
+ return;
881
+ }
882
+ else if (num == 0.0)
883
+ {
884
+ ArgumentOverflowErrorMessage(context,returnValue);
885
+ return;
886
+ }
887
+
888
+ returnValue->floatValue = CreateFloat(theEnv,log(num));
889
+ }
890
+
891
+ /***************************************/
892
+ /* Log10Function: H/L access routine */
893
+ /* for the log10 function. */
894
+ /***************************************/
895
+ void Log10Function(
896
+ Environment *theEnv,
897
+ UDFContext *context,
898
+ UDFValue *returnValue)
899
+ {
900
+ double num;
901
+
902
+ ClearErrorValue(theEnv);
903
+
904
+ if (! SingleNumberCheck(context,returnValue))
905
+ { return; }
906
+
907
+ num = CVCoerceToFloat(returnValue);
908
+ if (num < 0.0)
909
+ {
910
+ DomainErrorMessage(context,returnValue);
911
+ return;
912
+ }
913
+ else if (num == 0.0)
914
+ {
915
+ ArgumentOverflowErrorMessage(context,returnValue);
916
+ return;
917
+ }
918
+
919
+ returnValue->floatValue = CreateFloat(theEnv,log10(num));
920
+ }
921
+
922
+ /**************************************/
923
+ /* SqrtFunction: H/L access routine */
924
+ /* for the sqrt function. */
925
+ /**************************************/
926
+ void SqrtFunction(
927
+ Environment *theEnv,
928
+ UDFContext *context,
929
+ UDFValue *returnValue)
930
+ {
931
+ double num;
932
+
933
+ ClearErrorValue(theEnv);
934
+
935
+ if (! SingleNumberCheck(context,returnValue))
936
+ { return; }
937
+
938
+ num = CVCoerceToFloat(returnValue);
939
+ if (num < 0.00000)
940
+ {
941
+ DomainErrorMessage(context,returnValue);
942
+ return;
943
+ }
944
+
945
+ returnValue->floatValue = CreateFloat(theEnv,sqrt(num));
946
+ }
947
+
948
+ /*************************************/
949
+ /* PowFunction: H/L access routine */
950
+ /* for the pow function. */
951
+ /*************************************/
952
+ void PowFunction(
953
+ Environment *theEnv,
954
+ UDFContext *context,
955
+ UDFValue *returnValue)
956
+ {
957
+ UDFValue value1, value2;
958
+ double num1, num2;
959
+
960
+ ClearErrorValue(theEnv);
961
+
962
+ /*==================================*/
963
+ /* Check for two numeric arguments. */
964
+ /*==================================*/
965
+
966
+ if (! UDFNthArgument(context,1,NUMBER_BITS,&value1))
967
+ { return; }
968
+
969
+ if (! UDFNthArgument(context,2,NUMBER_BITS,&value2))
970
+ { return; }
971
+
972
+ /*=====================*/
973
+ /* Domain error check. */
974
+ /*=====================*/
975
+
976
+ num1 = CVCoerceToFloat(&value1);
977
+ num2 = CVCoerceToFloat(&value2);
978
+
979
+ if (((num1 == 0.0) && (num2 <= 0.0)) ||
980
+ ((num1 < 0.0) && (dtrunc(num2) != num2)))
981
+ {
982
+ DomainErrorMessage(context,returnValue);
983
+ return;
984
+ }
985
+
986
+ /*============================*/
987
+ /* Compute and set the value. */
988
+ /*============================*/
989
+
990
+ returnValue->floatValue = CreateFloat(theEnv,pow(num1,num2));
991
+ }
992
+
993
+ /*************************************/
994
+ /* ModFunction: H/L access routine */
995
+ /* for the mod function. */
996
+ /*************************************/
997
+ void ModFunction(
998
+ Environment *theEnv,
999
+ UDFContext *context,
1000
+ UDFValue *returnValue)
1001
+ {
1002
+ UDFValue item1, item2;
1003
+ double fnum1, fnum2;
1004
+ long long lnum1, lnum2;
1005
+
1006
+ /*==================================*/
1007
+ /* Check for two numeric arguments. */
1008
+ /*==================================*/
1009
+
1010
+ if (! UDFNthArgument(context,1,NUMBER_BITS,&item1))
1011
+ { return; }
1012
+
1013
+ if (! UDFNthArgument(context,2,NUMBER_BITS,&item2))
1014
+ { return; }
1015
+
1016
+ /*===========================*/
1017
+ /* Check for divide by zero. */
1018
+ /*===========================*/
1019
+
1020
+ if ((CVIsType(&item2,INTEGER_BIT) ? (item2.integerValue->contents == 0L) : false) ||
1021
+ (CVIsType(&item2,FLOAT_BIT) ? (item2.floatValue->contents == 0.0) : false))
1022
+ {
1023
+ DivideByZeroErrorMessage(theEnv,"mod");
1024
+ SetEvaluationError(theEnv,true);
1025
+ returnValue->integerValue = CreateInteger(theEnv,0);
1026
+ return;
1027
+ }
1028
+
1029
+ /*===========================*/
1030
+ /* Compute the return value. */
1031
+ /*===========================*/
1032
+
1033
+ if (CVIsType(&item1,FLOAT_BIT) || CVIsType(&item2,FLOAT_BIT))
1034
+ {
1035
+ fnum1 = CVCoerceToFloat(&item1);
1036
+ fnum2 = CVCoerceToFloat(&item2);
1037
+ returnValue->floatValue = CreateFloat(theEnv,fnum1 - (dtrunc(fnum1 / fnum2) * fnum2));
1038
+ }
1039
+ else
1040
+ {
1041
+ lnum1 = item1.integerValue->contents;
1042
+ lnum2 = item2.integerValue->contents;
1043
+
1044
+ if ((lnum1 == LLONG_MIN) && (lnum2 == -1))
1045
+ {
1046
+ ArgumentOverUnderflowErrorMessage(theEnv,"mod",true);
1047
+ SetEvaluationError(theEnv,true);
1048
+ returnValue->integerValue = CreateInteger(theEnv,0);
1049
+ return;
1050
+ }
1051
+
1052
+ returnValue->integerValue = CreateInteger(theEnv,lnum1 - (lnum1 / lnum2) * lnum2);
1053
+ }
1054
+ }
1055
+
1056
+ /************************************/
1057
+ /* PiFunction: H/L access routine */
1058
+ /* for the pi function. */
1059
+ /************************************/
1060
+ void PiFunction(
1061
+ Environment *theEnv,
1062
+ UDFContext *context,
1063
+ UDFValue *returnValue)
1064
+ {
1065
+ returnValue->floatValue = CreateFloat(theEnv,acos(-1.0));
1066
+ }
1067
+
1068
+ /****************************************/
1069
+ /* DegRadFunction: H/L access routine */
1070
+ /* for the deg-rad function. */
1071
+ /****************************************/
1072
+ void DegRadFunction(
1073
+ Environment *theEnv,
1074
+ UDFContext *context,
1075
+ UDFValue *returnValue)
1076
+ {
1077
+ if (! SingleNumberCheck(context,returnValue))
1078
+ { return; }
1079
+
1080
+ returnValue->floatValue = CreateFloat(theEnv,CVCoerceToFloat(returnValue) * PI / 180.0);
1081
+ }
1082
+
1083
+ /****************************************/
1084
+ /* RadDegFunction: H/L access routine */
1085
+ /* for the rad-deg function. */
1086
+ /****************************************/
1087
+ void RadDegFunction(
1088
+ Environment *theEnv,
1089
+ UDFContext *context,
1090
+ UDFValue *returnValue)
1091
+ {
1092
+ if (! SingleNumberCheck(context,returnValue))
1093
+ { return; }
1094
+
1095
+ returnValue->floatValue = CreateFloat(theEnv,CVCoerceToFloat(returnValue) * 180.0 / PI);
1096
+ }
1097
+
1098
+ /*****************************************/
1099
+ /* DegGradFunction: H/L access routine */
1100
+ /* for the deg-grad function. */
1101
+ /*****************************************/
1102
+ void DegGradFunction(
1103
+ Environment *theEnv,
1104
+ UDFContext *context,
1105
+ UDFValue *returnValue)
1106
+ {
1107
+ if (! SingleNumberCheck(context,returnValue))
1108
+ { return; }
1109
+
1110
+ returnValue->floatValue = CreateFloat(theEnv,CVCoerceToFloat(returnValue) / 0.9);
1111
+ }
1112
+
1113
+ /*****************************************/
1114
+ /* GradDegFunction: H/L access routine */
1115
+ /* for the grad-deg function. */
1116
+ /*****************************************/
1117
+ void GradDegFunction(
1118
+ Environment *theEnv,
1119
+ UDFContext *context,
1120
+ UDFValue *returnValue)
1121
+ {
1122
+ if (! SingleNumberCheck(context,returnValue))
1123
+ { return; }
1124
+
1125
+ returnValue->floatValue = CreateFloat(theEnv,CVCoerceToFloat(returnValue) * 0.9);
1126
+ }
1127
+
1128
+ /***************************************/
1129
+ /* RoundFunction: H/L access routine */
1130
+ /* for the round function. */
1131
+ /***************************************/
1132
+ void RoundFunction(
1133
+ Environment *theEnv,
1134
+ UDFContext *context,
1135
+ UDFValue *returnValue)
1136
+ {
1137
+ /*======================================*/
1138
+ /* Check that the argument is a number. */
1139
+ /*======================================*/
1140
+
1141
+ if (! UDFNthArgument(context,1,NUMBER_BITS,returnValue))
1142
+ { return; }
1143
+
1144
+ /*==============================*/
1145
+ /* Round float type to integer. */
1146
+ /*==============================*/
1147
+
1148
+ if (CVIsType(returnValue,FLOAT_BIT))
1149
+ { returnValue->integerValue = CreateInteger(theEnv,(long long) round(returnValue->floatValue->contents)); }
1150
+ }
1151
+
1152
+ /*******************************************/
1153
+ /* genacosh: Generic routine for computing */
1154
+ /* the hyperbolic arccosine. */
1155
+ /*******************************************/
1156
+ static double genacosh(
1157
+ double num)
1158
+ {
1159
+ return(log(num + sqrt(num * num - 1.0)));
1160
+ }
1161
+
1162
+ /*******************************************/
1163
+ /* genasinh: Generic routine for computing */
1164
+ /* the hyperbolic arcsine. */
1165
+ /*******************************************/
1166
+ static double genasinh(
1167
+ double num)
1168
+ {
1169
+ return(log(num + sqrt(num * num + 1.0)));
1170
+ }
1171
+
1172
+ /*******************************************/
1173
+ /* genatanh: Generic routine for computing */
1174
+ /* the hyperbolic arctangent. */
1175
+ /*******************************************/
1176
+ static double genatanh(
1177
+ double num)
1178
+ {
1179
+ return((0.5) * log((1.0 + num) / (1.0 - num)));
1180
+ }
1181
+
1182
+ /*******************************************/
1183
+ /* genasech: Generic routine for computing */
1184
+ /* the hyperbolic arcsecant. */
1185
+ /*******************************************/
1186
+ static double genasech(
1187
+ double num)
1188
+ {
1189
+ return(log(1.0 / num + sqrt(1.0 / (num * num) - 1.0)));
1190
+ }
1191
+
1192
+ /*******************************************/
1193
+ /* genacsch: Generic routine for computing */
1194
+ /* the hyperbolic arccosecant. */
1195
+ /*******************************************/
1196
+ static double genacsch(
1197
+ double num)
1198
+ {
1199
+ return(log(1.0 / num + sqrt(1.0 / (num * num) + 1.0)));
1200
+ }
1201
+
1202
+ /*******************************************/
1203
+ /* genacoth: Generic routine for computing */
1204
+ /* the hyperbolic arccotangent. */
1205
+ /*******************************************/
1206
+ static double genacoth(
1207
+ double num)
1208
+ {
1209
+ return((0.5) * log((num + 1.0) / (num - 1.0)));
1210
+ }
1211
+
1212
+ #endif
1213
+