/* PZT_complex_text.h, part of PoZeTools version 0.56, december 24, 2019. Copyright (c) 2002-2019 Pieter Suurmond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. String functions to read and write complex numbers from and to text format. */ /*----------------------------------------------------------------*/ /* Removes all whitespace, tabs newlines, carriage returns, etc. Also downcases all capitals. All DESTRUCTIVELY so take care! Returns length of string. May leave the string empty (""). */ int simplifyString (char* str); /*----------------------------------------------------------------*/ /* Cuts away all trailing zeros, and the dot, if nevessary. */ int cutTrailingZeroesAndDot(char* str); /*----------------------------------------------------------------------------*/ /* Reads complex number in polar or cartesian format in ASCIIZ string 'str'. Doesn't like whitespace and capitals, so apply 'simplifyString()' above, before calling 'readPolarAndCartesian()'. Writes both polar and cartesian format in 'p' and 'c' respectively. Returns 0 on success. Some valid expressions are: 0.98exp(0.3jpi) 0 0.2j exp(-0.3pij) j exp(-j) 0.01exp(pi) -2j 4exp(+22) 2exp(0) 2+0.77j +j exp(0j) j-2 0.6exp(0.2pij) */ int readPolarAndCartesian (char* str, complexPolar* p, complexCartesian* c); /*----------------------------------------------------------------------------*/ /* Writes the complex number 'p' in polar format into string 'str'. With argument 'decimals' you can specify the desired precision. */ void writePolar(const complexPolar* p, int decimals, char* str); /*----------------------------------------------------------------------------*/ /* Writes the complex number 'c' in rectangular format into string 'str'. With argument 'decimals' you can specify the desired precision, notice that decimals must be greater than zero. PS2019: argument decimals was an int up to version 0.55. */ void writeCartesian(const complexCartesian* c, signed char decimals, char* str); /*----------------------------------------------------------------------------------*/ /* Called by POZE_read() to emulate fget() from memory. And also by COEFF_read() for the same reason. */ int copy_line(char* lineBuff, int max, const char** source);