// ===================================================================================================================================== // allen_cpu_lib_trigonometry.c - Allen version 2.0 // ===================================================================================================================================== // // This file is part of the Allen Library. // Last modified: Saturday July 14, 2007. // // Copyright (c) 2007, Archville, BSD License. // A copy can be found here: http://www.opensource.org/licenses/bsd-license.php // Initally based on Salvatore Sanfilippo within Picol 0.1.0 // // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither the name of the Garabatos de licor nor the names of its contributors may // be used to endorse or promote products derived from this software // without specific prior written permission. // // This software is provided by the copyright holders and contributors // "as is" and any express or implied warranties, including, but not // limited to, the implied warranties of merchantability and fitness for // a particular purpose are disclaimed. in no event shall the copyright owner or // contributors be liable for any direct, indirect, incidental, special, // exemplary, or consequential damages (including, but not limited to, // procurement of substitute goods or services; loss of use, data, or // profits; or business interruption) however caused and on any theory of // liability, whether in contract, strict liability, or tort (including // negligence or otherwise) arising in any way out of the use of this // software, even if advised of the possibility of such damage. // ===================================================================================================================================== // Include libraries. // ===================================================================================================================================== #include // Standard input/output. #include // Standard C libraries. #include // String libraries. #include // Math libraries. #include // Types and conversion libraries. #include "allen_interpreter.h" // Main interpreter library. #include "allen_parser.h" // Main parser library. // ===================================================================================================================================== // Parameters. // ===================================================================================================================================== #define TLIB_TRIG_BSIZE 1024 // Buffer size. // ===================================================================================================================================== // Possible errors. // ===================================================================================================================================== #define TLIB_TRIG_EHLP "trig.?: command not found in library" // Error: Command not found in math library. // ===================================================================================================================================== // Tokens. // ==================================================================================================================================== #define TLIB_TRIG_SIN "trig.sin" // Sine. #define TLIB_TRIG_COS "trig.cos" // Cosine. #define TLIB_TRIG_TAN "trig.tan" // Tangent. #define TLIB_TRIG_SEC "trig.sec" // Secant. #define TLIB_TRIG_COSEC "trig.cosec" // Cosecant. #define TLIB_TRIG_COTAN "trig.cotan" // Cotangent. #define TLIB_TRIG_ASIN "trig.asin" // Arc sine. #define TLIB_TRIG_ACOS "trig.acos" // Arc cosine. #define TLIB_TRIG_ATAN "trig.atan" // Arc tangent. #define TLIB_TRIG_ASEC "trig.asec" // Arc secant. #define TLIB_TRIG_ACOSEC "trig.acosec" // Arc cosecant. #define TLIB_TRIG_ACOTAN "trig.acotan" // Arc cotangent. #define TLIB_TRIG_HSIN "trig.sinh" // Hyperbolic sine. #define TLIB_TRIG_HCOS "trig.cosh" // Hyperbolic cosine. #define TLIB_TRIG_HTAN "trig.tanh" // Hyperbolic tangent. #define TLIB_TRIG_HSEC "trig.sech" // Hyperbolic secant. #define TLIB_TRIG_HCOSEC "trig.cosech" // Hyperbolic cosecant. #define TLIB_TRIG_HCOTAN "trig.cotanh" // Hyperbolic cotangent. #define TLIB_TRIG_HASIN "trig.asinh" // Hyperbolic arc sine. #define TLIB_TRIG_HACOS "trig.acosh" // Hyperbolic arc cosine. #define TLIB_TRIG_HATAN "trig.atanh" // Hyperbolic arc tangent. #define TLIB_TRIG_HASEC "trig.asech" // Hyperbolic arc secant. #define TLIB_TRIG_HACOSEC "trig.acosech" // Hyperbolic arc cosecant. #define TLIB_TRIG_HACOTAN "trig.acotanh" // Hyperbolic arc cotangent. // ===================================================================================================================================== // Helper Function. // ===================================================================================================================================== #define TLIB_TRIG_HLP "trig.?" // Helper function. #define TLIB_TRIG_NIL "nil" // Null value. // ===================================================================================================================================== // Basic math operators. // ===================================================================================================================================== // Allows to perform regular trigonometric operations on value lists // and return results based on their expresions. // Index: Example: Result: // AllenVM_CPU_LIB_TRIG_SIN(); :: trig.sin -1 -0.841471 // AllenVM_CPU_LIB_TRIG_COS(); :: trig.cos 0 1.000000 // AllenVM_CPU_LIB_TRIG_TAN(); :: trig.tan 5 -3.380515 // AllenVM_CPU_LIB_TRIG_SEC(); :: trig.sec -1 1.850816 // AllenVM_CPU_LIB_TRIG_COSEC(); :: trig.cosec 20 1.095356 // AllenVM_CPU_LIB_TRIG_COTAN(); :: trig.cotan 10 1.542351 // AllenVM_CPU_LIB_TRIG_ASIN(); :: trig.asin 0.7 0.775397 // AllenVM_CPU_LIB_TRIG_ACOS(); :: trig.acos 0 1.570796 // AllenVM_CPU_LIB_TRIG_ATAN(); :: trig.atan 0.12 0.119429 // AllenVM_CPU_LIB_TRIG_ASEC(); :: trig.asec 2 1.047198 // AllenVM_CPU_LIB_TRIG_ACOSEC(); :: trig.acosec 2 0.523599 // AllenVM_CPU_LIB_TRIG_ACOTAN(); :: trig.acotan 2 0.463648 // AllenVM_CPU_LIB_TRIG_HSIN(); :: trig.sinh 5 74.203209 // AllenVM_CPU_LIB_TRIG_HCOS(); :: trig.cosh 4 27.308233 // AllenVM_CPU_LIB_TRIG_HTAN(); :: trig.tanh 9 1.000000 // AllenVM_CPU_LIB_TRIG_HSEC(); :: trig.sech 0 1.000000 // AllenVM_CPU_LIB_TRIG_HCOSEC(); :: trig.cosech 0.5 1.919035 // AllenVM_CPU_LIB_TRIG_HCOTAN(); :: trig.cotanh 0.5 2.163953 // AllenVM_CPU_LIB_TRIG_HASIN(); :: trig.asinh 2 1.443635 // AllenVM_CPU_LIB_TRIG_HACOS(); :: trig.acosh 2 1.316958 // AllenVM_CPU_LIB_TRIG_HATAN(); :: trig.atanh 0.4 0.423649 // AllenVM_CPU_LIB_TRIG_HASEC(); :: trig.asech 0.4 1.566799 // AllenVM_CPU_LIB_TRIG_HACOSEC(); :: trig.acosech 1 0.881374 // AllenVM_CPU_LIB_TRIG_HACOTAN(); :: trig.acotanh 20 0.050042 // Total: 24. // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_SIN(); // Purpose: Sine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_SIN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = sin(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_COS(); // Purpose: Cosine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_COS(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = cos(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_TAN(); // Purpose: Tangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_TAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = tan(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_SEC(); // Purpose: Secant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_SEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = 1.0 / cos(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_COSEC(); // Purpose: Cosecant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_COSEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = 1.0 / sin(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_COTAN(); // Purpose: Cotangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_COTAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = 1.0 / tan(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ASIN(); // Purpose: Arc Sine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_ASIN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = asin(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ACOS(); // Purpose: Arc Cosine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_ACOS(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = acos(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ATAN(); // Purpose: Arc Tangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_ATAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = atan(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ASEC(); // Purpose: Arc Secant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_ASEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = acos(1.0 / atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ACOSEC(); // Purpose: Arc Cosecant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_ACOSEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = asin(1.0 / atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ACOTAN(); // Purpose: Arc Cotangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_ACOTAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = atan(1.0 / atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HSIN(); // Purpose: Hyperbolic Sine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HSIN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = sinh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HCOS(); // Purpose: Hyperbolic Cosine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HCOS(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = cosh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HTAN(); // Purpose: Hyperbolic Tangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HTAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = tanh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HSEC(); // Purpose: Hyperbolic Secant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HSEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = 1.0 / cosh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HCOSEC(); // Purpose: Hyperbolic Cosecant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HCOSEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = 1.0 / sinh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HCOTAN(); // Purpose: Hyperbolic Cotangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HCOTAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = 1.0 / tanh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HASIN(); // Purpose: Hyperbolic Arc sine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HASIN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = asinh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HACOS(); // Purpose: Hyperbolic Arc Cosine. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HACOS(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = acosh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HATAN(); // Purpose: Hyperbolic Arc Tangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HATAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = atanh(atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HASEC(); // Purpose: Hyperbolic Arc Secant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HASEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = acosh(1.0 / atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HACOSEC(); // Purpose: Hyperbolic Arc Cosecant. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HACOSEC(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = asinh(1.0 / atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HACOTAN(); // Purpose: Hyperbolic Arc Cotangent. // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HACOTAN(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. float c = atanh(1.0 / atof(argv[1])); // Calculate. char buf[TLIB_TRIG_BSIZE]; // Create buffer. snprintf(buf,TLIB_TRIG_BSIZE,"%f",c); // Copy result to buffer as float. AllenVM_InterpSetResult(i,buf); // Set interpreter result. return Allen_VM_OK; // Everything ok. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_HLP(); // Purpose: Adds help facilities // Returns: Expression result. // ------------------------------------------------------------------------------------------------------------------------------------- static int AllenVM_CPU_LIB_TRIG_HLP(struct AllenInterp *i, int argc, char **argv, void *pd) { if(argc != 2) return AllenVM_CPU_Error(i,argv[0]); // Check parameters. if(!strcmp(TLIB_TRIG_SIN,argv[1])) { // Compare parameters. puts("Description: Returns the sine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.sin -1 => -0.841471"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_SIN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_COS,argv[1])) { // Compare parameters. puts("Description: Returns the cosine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.cos 0 => 1.000000"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_COS); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_TAN,argv[1])) { // Compare parameters. puts("Description: Returns the tangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.tan 5 => -3.380515"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_TAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_SEC,argv[1])) { // Compare parameters. puts("Description: Returns the secant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.sec -1 => 1.850816"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_SEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_COSEC,argv[1])) { // Compare parameters. puts("Description: Returns the cosecant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.cosec 20 => 1.095356"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_COSEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_COTAN,argv[1])) { // Compare parameters. puts("Description: Returns the cotangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.cotan 10 => 1.542351"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_COTAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_ASIN,argv[1])) { // Compare parameters. puts("Description: Returns the arc sine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.asin 0.7 => -0.775397"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_ASIN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_ACOS,argv[1])) { // Compare parameters. puts("Description: Returns the arc cosine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.acos 0 => 1.570796"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_ACOS); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_ATAN,argv[1])) { // Compare parameters. puts("Description: Returns the arc tangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.atan 0.12 => 0.119429"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_ATAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_ASEC,argv[1])) { // Compare parameters. puts("Description: Returns the arc secant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.asec 2 => 1.047198"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_ASEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_ACOSEC,argv[1])) { // Compare parameters. puts("Description: Returns the arc cosecant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.acosec 2 => 0.523599"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_ACOSEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_ACOTAN,argv[1])) { // Compare parameters. puts("Description: Returns the arc cotangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.acotan 2 => 0.463648"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_ACOTAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HSIN,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic sine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.sinh 5 => 74.203209"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HSIN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HCOS,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic cosine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.cosh 4 => 27.308233"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HCOS); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HTAN,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic tangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.tanh 9 => 1.000000"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HTAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HSEC,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic secant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.sech 0 => 1.000000"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HSEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HCOSEC,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic cosecant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.cosech 0.5 => 1.919035"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HCOSEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HCOTAN,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic cotangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.cotanh 0.5 => 2.163953"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HCOTAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HASIN,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic arc sine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.asinh 2 => 1.443635"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HASIN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HACOS,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic arc cosine of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.acosh 2 => 1.316958"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HACOS); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HATAN,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic arc tangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.atanh 0.4 => 0.423649"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HATAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HASEC,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic arc secant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.asech 0.4 => 1.566799"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HASEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HACOSEC,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic arc cosecant of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.acosech 1 => 0.881374"); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HACOSEC); // Set interpreter result. return Allen_VM_OK; } // Everything ok. if(!strcmp(TLIB_TRIG_HACOTAN,argv[1])) { // Compare parameters. puts("Description: Returns the hyperbolic arc cotangent of arg."); // Description. puts("Returns: Float number from expression result."); // Returns. puts("Sample: trig.acotanh 20 => 0.050042 "); // Sample function. puts("Parameters: min: 1 max: 1"); // Parameters needed. AllenVM_InterpSetResult(i,TLIB_TRIG_HACOTAN); // Set interpreter result. return Allen_VM_OK; } // Everything ok. AllenVM_InterpSetResult(i,TLIB_TRIG_NIL); // Set interpreter result. return AllenVM_CPU_Error(i,TLIB_TRIG_EHLP); // Command not found. } // ------------------------------------------------------------------------------------------------------------------------------------- // Function: AllenVM_CPU_LIB_TRIG_ADD(); // Purpose: Add instructions to the CPU. // Returns: Void (nothing). // ------------------------------------------------------------------------------------------------------------------------------------- void AllenVM_CPU_LIB_TRIG_ADD(struct AllenInterp *i) { AllenVM_InterpSetCommand(i,TLIB_TRIG_SIN, AllenVM_CPU_LIB_TRIG_SIN, NULL); // Sine. AllenVM_InterpSetCommand(i,TLIB_TRIG_COS, AllenVM_CPU_LIB_TRIG_COS, NULL); // Cosine. AllenVM_InterpSetCommand(i,TLIB_TRIG_TAN, AllenVM_CPU_LIB_TRIG_TAN, NULL); // Tangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_SEC, AllenVM_CPU_LIB_TRIG_SEC, NULL); // Secant. AllenVM_InterpSetCommand(i,TLIB_TRIG_COSEC, AllenVM_CPU_LIB_TRIG_COSEC, NULL); // Cosecant. AllenVM_InterpSetCommand(i,TLIB_TRIG_COTAN, AllenVM_CPU_LIB_TRIG_COTAN, NULL); // Cotangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_ASIN, AllenVM_CPU_LIB_TRIG_ASIN, NULL); // Arc Sine. AllenVM_InterpSetCommand(i,TLIB_TRIG_ACOS, AllenVM_CPU_LIB_TRIG_ACOS, NULL); // Arc Cosine. AllenVM_InterpSetCommand(i,TLIB_TRIG_ATAN, AllenVM_CPU_LIB_TRIG_ATAN, NULL); // Arc Tangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_ASEC, AllenVM_CPU_LIB_TRIG_ASEC, NULL); // Arc Secant. AllenVM_InterpSetCommand(i,TLIB_TRIG_ACOSEC, AllenVM_CPU_LIB_TRIG_ACOSEC, NULL); // Arc Cosecant. AllenVM_InterpSetCommand(i,TLIB_TRIG_ACOTAN, AllenVM_CPU_LIB_TRIG_ACOTAN, NULL); // Arc Cotangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_HSIN, AllenVM_CPU_LIB_TRIG_HSIN, NULL); // Hyperbolic Sine. AllenVM_InterpSetCommand(i,TLIB_TRIG_HCOS, AllenVM_CPU_LIB_TRIG_HCOS, NULL); // Hyperbolic Cosine. AllenVM_InterpSetCommand(i,TLIB_TRIG_HTAN, AllenVM_CPU_LIB_TRIG_HTAN, NULL); // Hyperbolic Tangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_HSEC, AllenVM_CPU_LIB_TRIG_HSEC, NULL); // Hyperbolic Secant. AllenVM_InterpSetCommand(i,TLIB_TRIG_HCOSEC, AllenVM_CPU_LIB_TRIG_HCOSEC, NULL); // Hyperbolic Cosecant. AllenVM_InterpSetCommand(i,TLIB_TRIG_HCOTAN, AllenVM_CPU_LIB_TRIG_HCOTAN, NULL); // Hyperbolic Cotangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_HASIN, AllenVM_CPU_LIB_TRIG_HASIN, NULL); // Hyperbolic Arc Sine. AllenVM_InterpSetCommand(i,TLIB_TRIG_HACOS, AllenVM_CPU_LIB_TRIG_HACOS, NULL); // Hyperbolic Arc Cosine. AllenVM_InterpSetCommand(i,TLIB_TRIG_HATAN, AllenVM_CPU_LIB_TRIG_HATAN, NULL); // Hyperbolic Arc Tangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_HASEC, AllenVM_CPU_LIB_TRIG_HASEC, NULL); // Hyperbolic Arc Secant. AllenVM_InterpSetCommand(i,TLIB_TRIG_HACOSEC, AllenVM_CPU_LIB_TRIG_HACOSEC, NULL); // Hyperbolic Arc Cosecant. AllenVM_InterpSetCommand(i,TLIB_TRIG_HACOTAN, AllenVM_CPU_LIB_TRIG_HACOTAN, NULL); // Hyperbolic Arc Cotangent. AllenVM_InterpSetCommand(i,TLIB_TRIG_HLP, AllenVM_CPU_LIB_TRIG_HLP, NULL); // Helper function. } // ===================================================================================================================================== // EOF // ===================================================================================================================================== // Compiler parameters: Gcc -O2 -lm // Recommended editor: Scite/Gedit/Vim.