mirror of
https://gitlab.com/rnger/amath
synced 2025-12-08 14:58:29 +00:00
Release 1.8.0
This commit is contained in:
@@ -14,3 +14,4 @@ catalog/flexcat/flexcat
|
||||
*_.3
|
||||
doxygen.warn
|
||||
*.deb
|
||||
Makefile
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
-------------------------------------------------------------------------------
|
||||
--- amath change history ---
|
||||
-------------------------------------------------------------------------------
|
||||
amath release history
|
||||
|
||||
v1.8.0 April 13 2017
|
||||
- Fixed bugs in numeral systems.
|
||||
- Fixed bugs related to infinity (Inf).
|
||||
- Fixed bugs related to Not a Number (NaN).
|
||||
- Updated and cleanup documentation.
|
||||
- Cleaned up code structure.
|
||||
- OpenLibm support.
|
||||
|
||||
v1.7.1 March 26 2017
|
||||
- Haiku support.
|
||||
@@ -8,8 +14,8 @@ v1.7.1 March 26 2017
|
||||
- Code cleanup.
|
||||
|
||||
v1.7.0 March 12 2017
|
||||
- Introduce scientific notation.
|
||||
- Introduce Not a Number (NaN).
|
||||
- Introduced scientific notation.
|
||||
- Introduced Not a Number (NaN).
|
||||
- Fixed bugs related to infinity (Inf).
|
||||
- Fixed bugs in log of complex numbers.
|
||||
- Fixed bugs in numeral systems.
|
||||
@@ -34,7 +40,7 @@ v1.6.3 February 03 2017
|
||||
|
||||
v1.6.2 January 24 2017
|
||||
- Fixed bug in memory allocation.
|
||||
- Fixed bug in native keybord input.
|
||||
- Fixed bug in native keyboard input.
|
||||
- Included build options in executables.
|
||||
- ARM support.
|
||||
|
||||
|
||||
@@ -29,7 +29,4 @@ Install by copying the desired amath binary to C: or any other appropriate locat
|
||||
> amath version
|
||||
|
||||
Run regression tests:
|
||||
> amath-test test
|
||||
|
||||
Load amath into memory:
|
||||
> resident amath pure
|
||||
> amath test
|
||||
|
||||
@@ -1,21 +1,37 @@
|
||||
.TH "amath" 1 "Wed Mar 15 2017" "Version 1.7.1" "amath" \" -*- nroff -*-
|
||||
.ad l
|
||||
.nh
|
||||
.\" Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. 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.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
.TH amath 1 "Version 1.8.0" "April 13 2017"
|
||||
.SH NAME
|
||||
amath \- Simple command line calculator
|
||||
|
||||
.SH SYNOPSIS
|
||||
\fCamath [ --shell | --noansi | expression ]\fP
|
||||
|
||||
.SH Description
|
||||
\fC[ --noansi ] [ --shell | expression ]\fP
|
||||
.SH DESCRIPTION
|
||||
amath(1) features a case sensitive command line interface, internal
|
||||
IEEE 754 calculations with 15 significant digits, calculations with
|
||||
real and complex numbers, variables and user defined functions,
|
||||
logarithmic and exponential functions, trigonometric and hyperbolic
|
||||
function and selected mathematical constants and rounding functions.
|
||||
|
||||
.SH "Statements"
|
||||
.PP
|
||||
.SH Statements
|
||||
.nf
|
||||
clear Clear console window
|
||||
def Define function
|
||||
@@ -36,9 +52,7 @@ version Show version string
|
||||
memory Show internal memory usage
|
||||
exit Exit program
|
||||
.fi
|
||||
|
||||
.SH "Operators"
|
||||
.PP
|
||||
.SH Operators
|
||||
.nf
|
||||
+ Mathematical addition
|
||||
- Mathematical subtraction
|
||||
@@ -47,18 +61,14 @@ exit Exit program
|
||||
^ Mathematical exponentiation
|
||||
= Assignment of variable values
|
||||
| Absolute value of number
|
||||
|
||||
.SH "Variables and constant"
|
||||
.PP
|
||||
.SH Variables and constant
|
||||
.nf
|
||||
pi Trigonometric constant
|
||||
e Euler's number
|
||||
i Imaginary unit
|
||||
ins Result of last calculation
|
||||
.fi
|
||||
|
||||
.SH "Base functions"
|
||||
.PP
|
||||
.SH Base functions
|
||||
.nf
|
||||
abs Absolute value of number
|
||||
sgn Mathematical signum function
|
||||
@@ -72,9 +82,7 @@ lb Binary logarithm function (base 2)
|
||||
ln Natural logarithm function (base e)
|
||||
lg Common logarithm function (base 10)
|
||||
.fi
|
||||
|
||||
.SH "Trigonometric functions"
|
||||
.PP
|
||||
.SH Trigonometric functions
|
||||
.nf
|
||||
sin Trigonometric sine function
|
||||
cos Trigonometric cosine function
|
||||
@@ -82,16 +90,20 @@ tan Trigonometric tangent function
|
||||
cot Trigonometric cotangent function
|
||||
sec Trigonometric secant function
|
||||
csc Trigonometric cosecant function
|
||||
crd Trigonometric chord function
|
||||
exsec Trigonometric exsecant function
|
||||
excsc Trigonometric excosecant function
|
||||
arcsin Inverse trigonometric sine function
|
||||
arccos Inverse trigonometric cosine function
|
||||
arctan Inverse trigonometric tangent function
|
||||
arccot Inverse trigonometric cotangent function
|
||||
arcsec Inverse trigonometric secant function
|
||||
arccsc Inverse trigonometric cosecant function
|
||||
arccrd Inverse trigonometric chord function
|
||||
arcexsec Inverse trigonometric exsecant function
|
||||
arcexcsc Inverse trigonometric excosecant function
|
||||
.fi
|
||||
|
||||
.SH "Hyperbolic functions"
|
||||
.PP
|
||||
.SH Hyperbolic functions
|
||||
.nf
|
||||
sinh Hyperbolic sine function
|
||||
cosh Hyperbolic cosine function
|
||||
@@ -106,9 +118,7 @@ arccoth Inverse hyperbolic cotangent function
|
||||
arcsech Inverse hyperbolic secant function
|
||||
arccsch Inverse hyperbolic cosecant function
|
||||
.fi
|
||||
|
||||
.SH "Early trigonometric functions"
|
||||
.PP
|
||||
.SH Early trigonometric functions
|
||||
.nf
|
||||
ver Versed sine function
|
||||
vcs Versed cosine function
|
||||
@@ -127,9 +137,7 @@ archvc Inverse haversed cosine function
|
||||
archcv Inverse hacoversed sine function
|
||||
archcc Inverse hacoversed cosine function
|
||||
.fi
|
||||
|
||||
.SH "Example script"
|
||||
.PP
|
||||
.SH Example script
|
||||
.nf
|
||||
round(1.5461);round(-1.5461);
|
||||
ceil(43.5461);ceil(-43.5461);
|
||||
@@ -137,9 +145,7 @@ floor(39.9531);floor(-39.9531);
|
||||
trunc(23.827);trunc(-23.827);
|
||||
sqrt(100);sqrt(52.23);
|
||||
.fi
|
||||
|
||||
.SH "Example script with functions"
|
||||
.PP
|
||||
.SH Example script with functions
|
||||
.nf
|
||||
f(x)=x*2+1;
|
||||
g(y)=y^2+y*1.5+2;
|
||||
@@ -147,9 +153,7 @@ a=2;b=3;c=a+b;
|
||||
vars;funcs;
|
||||
f(2.2);c+1.1;
|
||||
.fi
|
||||
|
||||
.SH "Example script with complex numbers"
|
||||
.PP
|
||||
.SH Example script with complex numbers
|
||||
.nf
|
||||
cos(1+2i);
|
||||
sin(1+2i);
|
||||
@@ -158,7 +162,17 @@ coth(1+2i);
|
||||
sech(1+2i);
|
||||
csch(1+2i);
|
||||
.fi
|
||||
|
||||
.SH "See also"
|
||||
.SH HOMEPAGE
|
||||
http://amath.innolan.net/
|
||||
.SH AUTHORS
|
||||
.PP
|
||||
amathc(3), amathr(3), amathi(3)
|
||||
Written by Carsten Sonne Larsen <cs@innolan.net>. The code in MemSet and
|
||||
MemCopy is derived from software contributed to Berkeley by Mike Hibler and
|
||||
Chris Torek. The code in complex calculations is derived from software
|
||||
written by Stephen L. Moshier.
|
||||
.SH COPYRIGHT
|
||||
Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
.br
|
||||
Copyright (c) 1990, 1993 The Regents of the University of California
|
||||
.SH SEE ALSO
|
||||
amathc(3), amathr(3), amathi(3)
|
||||
+6
-2210
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
version="1.7.1"
|
||||
version="1.8.0"
|
||||
|
||||
build_package () {
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#! /bin/sh
|
||||
|
||||
# DO NOT USE THIS SCRIPT UNLESS YOU KNOW WHAT YOU ARE DOING !
|
||||
|
||||
version='1.8.0'
|
||||
stamp="201704130000"
|
||||
#stamp="201704110000"
|
||||
srcdir="amath-rc"
|
||||
distdir="amath-${version}"
|
||||
cd ..
|
||||
|
||||
rm -f amath-${version}.tar.gz
|
||||
rm -Rf amath-${version}
|
||||
|
||||
mkdir -m 775 ${distdir}
|
||||
mkdir -m 775 ${distdir}/src/
|
||||
mkdir -m 775 ${distdir}/src/clib/
|
||||
mkdir -m 775 ${distdir}/src/cplex/
|
||||
mkdir -m 775 ${distdir}/src/lib/
|
||||
mkdir -m 775 ${distdir}/src/loc/
|
||||
mkdir -m 775 ${distdir}/src/real/
|
||||
mkdir -m 775 ${distdir}/src/system/
|
||||
mkdir -m 775 ${distdir}/src/main/
|
||||
mkdir -m 775 ${distdir}/src/main/function
|
||||
mkdir -m 775 ${distdir}/src/main/statement/
|
||||
mkdir -m 775 ${distdir}/script/
|
||||
mkdir -m 775 ${distdir}/text/
|
||||
mkdir -m 775 ${distdir}/catalog/
|
||||
mkdir -m 775 ${distdir}/catalog/english/
|
||||
mkdir -m 775 ${distdir}/build/
|
||||
mkdir -m 775 ${distdir}/build/flexcat/
|
||||
|
||||
install -m 664 ${srcdir}/src/*.h ${distdir}/src/
|
||||
install -m 664 ${srcdir}/src/*.cpp ${distdir}/src/
|
||||
install -m 664 ${srcdir}/src/clib/* ${distdir}/src/clib/
|
||||
install -m 664 ${srcdir}/src/cplex/* ${distdir}/src/cplex/
|
||||
install -m 664 ${srcdir}/src/lib/* ${distdir}/src/lib/
|
||||
install -m 664 ${srcdir}/src/loc/* ${distdir}/src/loc/
|
||||
install -m 664 ${srcdir}/src/real/* ${distdir}/src/real/
|
||||
install -m 664 ${srcdir}/src/system/* ${distdir}/src/system/
|
||||
install -m 664 ${srcdir}/src/main/*.h ${distdir}/src/main/
|
||||
install -m 664 ${srcdir}/src/main/*.cpp ${distdir}/src/main/
|
||||
install -m 664 ${srcdir}/src/main/function/* ${distdir}/src/main/function/
|
||||
install -m 664 ${srcdir}/src/main/statement/* ${distdir}/src/main/statement/
|
||||
install -m 664 ${srcdir}/script/* ${distdir}/script/
|
||||
install -m 664 ${srcdir}/text/* ${distdir}/text/
|
||||
install -m 664 ${srcdir}/catalog/english/* ${distdir}/catalog/english/
|
||||
install -m 664 ${srcdir}/build/flexcat/* ${distdir}/build/flexcat/
|
||||
install -m 664 ${srcdir}/HISTORY ${distdir}/
|
||||
install -m 664 ${srcdir}/LICENSE ${distdir}/
|
||||
install -m 664 ${srcdir}/README ${distdir}/
|
||||
install -m 664 ${srcdir}/amath.1 ${distdir}/
|
||||
install -m 775 ${srcdir}/configure ${distdir}/
|
||||
install -m 775 ${srcdir}/builddist ${distdir}/
|
||||
install -m 775 ${srcdir}/buildwin ${distdir}/
|
||||
|
||||
chown -R 1000:1000 ${distdir}
|
||||
|
||||
for f in $(find ${distdir} -name '*'); do touch -amt ${stamp}.00 $f; done
|
||||
tar --numeric-owner -cvzf amath-${version}.tar.gz ${distdir}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
version="1.7.1"
|
||||
version="1.8.0"
|
||||
|
||||
echo "Building amath ${version} for Windows ..."
|
||||
|
||||
@@ -22,20 +22,20 @@ make static
|
||||
mv amath dist/amath-${version}-x64.exe
|
||||
make clean
|
||||
|
||||
cd dist
|
||||
touch hashkeys
|
||||
sha1sum amath-${version}-x86.exe >>hashkeys
|
||||
sha1sum amath-${version}-x86.exe >>hashkeys
|
||||
sha256sum amath-${version}-x86.exe >>hashkeys
|
||||
sha256sum amath-${version}-x86.exe >>hashkeys
|
||||
cd ..
|
||||
#cd dist
|
||||
#touch hashkeys.txt
|
||||
#sha1sum amath-${version}-x86.exe >>hashkeys.txt
|
||||
#sha1sum amath-${version}-x86.exe >>hashkeys.txt
|
||||
#sha256sum amath-${version}-x86.exe >>hashkeys.txt
|
||||
#sha256sum amath-${version}-x86.exe >>hashkeys.txt
|
||||
#cd ..
|
||||
|
||||
cp LICENSE dist/
|
||||
cp HISTORY dist/
|
||||
tr '\n' '\r' <LICENSE >dist/license.txt
|
||||
tr '\n' '\r' <HISTORY >dist/changes.txt
|
||||
|
||||
mkdir dist/script
|
||||
cp script/* dist/script/
|
||||
date -Ru >dist/build_date
|
||||
date -Ru >dist/build.txt
|
||||
|
||||
mv dist amath
|
||||
zip -r amath-${version}.zip amath/*
|
||||
|
||||
@@ -27,68 +27,145 @@
|
||||
|
||||
set -e
|
||||
|
||||
version="1.7.1"
|
||||
version="1.8.0"
|
||||
|
||||
clang=false
|
||||
debugsym=false
|
||||
regtest=true
|
||||
openlibm=false
|
||||
stdlibm=false
|
||||
stdlibc=false
|
||||
useldconfig=false
|
||||
|
||||
prefix="/usr"
|
||||
pkgconfigdir="lib/pkgconfig"
|
||||
mandir="share/man"
|
||||
cflags=""
|
||||
cxxflags=""
|
||||
ldflags=""
|
||||
gcclib="-lstdc++"
|
||||
libm=""
|
||||
|
||||
for arg in "$@"; do
|
||||
unknown=true
|
||||
case "$arg" in
|
||||
--prefix=*)
|
||||
prefix=`echo $arg | sed 's/--prefix=//'`
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--pkgconfig=*)
|
||||
pkgconfigdir=`echo $arg | sed 's/--pkgconfig=//'`
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--mandir=*)
|
||||
mandir=`echo $arg | sed 's/--mandir=//'`
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--cross-compile=*)
|
||||
crosscompile=`echo $arg | sed 's/--cross-compile=//'`
|
||||
crosscompile="${crosscompile}-"
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
CFLAGS=*)
|
||||
cflags=`echo $arg | sed 's/CFLAGS=//'`
|
||||
cflags="${cflags} "
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
CXXFLAGS=*)
|
||||
cxxflags=`echo $arg | sed 's/CXXFLAGS=//'`
|
||||
cxxflags="${cxxflags} "
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
LDFLAGS=*)
|
||||
ldflags=`echo $arg | sed 's/LDFLAGS=//'`
|
||||
ldflags="${ldflags} "
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--enable-clang)
|
||||
clang=true;;
|
||||
--disable-clang)
|
||||
clang=false;;
|
||||
clang=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--disable-clang)
|
||||
clang=false
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--enable-ldconfig)
|
||||
useldconfig=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--disable-ldconfig)
|
||||
useldconfig=false
|
||||
unknown=false
|
||||
;;
|
||||
--enable-debug)
|
||||
debugsym=true;;
|
||||
debugsym=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--disable-debug)
|
||||
debugsym=false;;
|
||||
debugsym=false
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--enable-test)
|
||||
regtest=true;;
|
||||
regtest=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--disable-test)
|
||||
regtest=false;;
|
||||
regtest=false
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--with-libm)
|
||||
stdlibm=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--without-libm)
|
||||
stdlibm=false
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--with-openlibm)
|
||||
openlibm=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--without-openlibm)
|
||||
openlibm=false
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--with-stdc++)
|
||||
gcclib="-lstdc++";;
|
||||
gcclib="-lstdc++"
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--without-stdc++)
|
||||
gcclib="";;
|
||||
gcclib=""
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--with-libc)
|
||||
stdlibc=true
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--without-libc)
|
||||
stdlibc=false
|
||||
unknown=false
|
||||
;;
|
||||
|
||||
--help)
|
||||
echo "amath configure script ${version}"
|
||||
@@ -97,6 +174,7 @@ for arg in "$@"; do
|
||||
echo 'options:'
|
||||
echo ' --prefix=<path>: installation prefix'
|
||||
echo ' --pkgconfig=<path>: pkg-config path (without prefix)'
|
||||
echo ' --mandir=<path>: manpage path (without prefix)'
|
||||
echo ' --cross-compile=<prefix>: cross compiler prefix'
|
||||
echo ' --enable-debug: include debug symbols'
|
||||
echo ' --disable-debug: do not include debug symbols'
|
||||
@@ -104,17 +182,29 @@ for arg in "$@"; do
|
||||
echo ' --disable-test: do not include regression test'
|
||||
echo ' --enable-clang: build with clang compiler'
|
||||
echo ' --disable-clang: do not build with clang compiler'
|
||||
echo ' --with-stdc++: link with stdc++ library'
|
||||
echo ' --enable-ldconfig: use ldconfig to registre libraries'
|
||||
echo ' --disable-ldconfig: do not use ldconfig to registre libraries'
|
||||
echo ' --with-libm: link with libm library (-lm)'
|
||||
echo ' --without-libm: do not link with libm library'
|
||||
echo ' --with-openlibm: link with openlibm library (-lopenlibm)'
|
||||
echo ' --without-openlibm: do not link with openlibm library'
|
||||
echo ' --with-stdc++: link with stdc++ library (-lstdc++)'
|
||||
echo ' --without-stdc++: do not link with stdc++ library'
|
||||
echo ' --with-libc: explicit link with libc library (-lc)'
|
||||
echo ' --without-libc: do not link with libc library'
|
||||
echo
|
||||
echo ' CFLAGS=<flags>: additional compiler flags'
|
||||
echo ' CXXFLAGS=<flags>: additional compiler flags'
|
||||
echo ' LDFLAGS=<flags>: additional linker flags'
|
||||
echo
|
||||
echo 'No warnings are shown for Invalid options.'
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if $unknown; then
|
||||
echo "Invalid option $arg"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
if $clang; then
|
||||
@@ -135,12 +225,39 @@ if $debugsym; then
|
||||
appop="-O0 -g"
|
||||
libop="-O0 -g"
|
||||
exestrip=""
|
||||
debugflag="-DDEBUG "
|
||||
else
|
||||
appop="-O2"
|
||||
libop="-O3"
|
||||
exestrip="-s"
|
||||
debugflag=""
|
||||
fi
|
||||
|
||||
dlibm=false
|
||||
mflags=""
|
||||
if $stdlibm; then
|
||||
libm="-lm "
|
||||
mflags="-DLIBM "
|
||||
dlibm=true
|
||||
fi
|
||||
|
||||
if $openlibm; then
|
||||
libm="-lopenlibm "
|
||||
mflags="-DLIBM "
|
||||
dlibm=true
|
||||
fi
|
||||
|
||||
if $useldconfig; then
|
||||
soverion=".${version}"
|
||||
else
|
||||
soverion=""
|
||||
fi
|
||||
|
||||
if $stdlibc; then
|
||||
gcclib="${gcclib} -lc"
|
||||
fi
|
||||
|
||||
cflags="${cflags}${debugflag}${mflags}"
|
||||
cxxflags="${cflags} ${cxxflags}"
|
||||
|
||||
APPSRCS='
|
||||
@@ -184,6 +301,7 @@ FUNCTIONSRC='
|
||||
absolute.cpp
|
||||
aexcosecant.cpp
|
||||
aexsecant.cpp
|
||||
arcchord.cpp
|
||||
arccos.cpp
|
||||
arcsin.cpp
|
||||
arctan.cpp
|
||||
@@ -199,6 +317,7 @@ archaversine.cpp
|
||||
arcvercosine.cpp
|
||||
arcversine.cpp
|
||||
ceil.cpp
|
||||
chord.cpp
|
||||
cosecant.cpp
|
||||
cosine.cpp
|
||||
cotangent.cpp
|
||||
@@ -269,38 +388,34 @@ version.cpp
|
||||
'
|
||||
LIBAPPSRCS='
|
||||
aengine.cpp
|
||||
bigint.cpp
|
||||
charbuf.cpp
|
||||
integer.cpp
|
||||
cplex.cpp
|
||||
nnumb.cpp
|
||||
ntext.cpp
|
||||
ntextd.cpp
|
||||
ntextp.cpp
|
||||
real.cpp
|
||||
'
|
||||
LIBREALSRCS='
|
||||
acos.c
|
||||
acosh.c
|
||||
acvs.c
|
||||
ahv.c
|
||||
ahvc.c
|
||||
asin.c
|
||||
asinh.c
|
||||
atan.c
|
||||
atan2.c
|
||||
atanh.c
|
||||
aver.c
|
||||
cbrt.c
|
||||
ceil.c
|
||||
copysign.c
|
||||
csign.c
|
||||
cos.c
|
||||
cosh.c
|
||||
exp.c
|
||||
expm1.c
|
||||
fabs.c
|
||||
finite.c
|
||||
floor.c
|
||||
fmod.c
|
||||
hypot.c
|
||||
isnan.c
|
||||
kcos.c
|
||||
kremp2.c
|
||||
ksin.c
|
||||
@@ -319,39 +434,79 @@ tan.c
|
||||
tanh.c
|
||||
trunc.c
|
||||
'
|
||||
LIBREAL2SRCS='
|
||||
acot.c
|
||||
acoth.c
|
||||
acrd.c
|
||||
acsc.c
|
||||
acsch.c
|
||||
acvc.c
|
||||
acvs.c
|
||||
aexc.c
|
||||
aexs.c
|
||||
ahcc.c
|
||||
ahcv.c
|
||||
ahv.c
|
||||
ahvc.c
|
||||
asec.c
|
||||
asech.c
|
||||
avcs.c
|
||||
aver.c
|
||||
cot.c
|
||||
coth.c
|
||||
crd.c
|
||||
csc.c
|
||||
csch.c
|
||||
cvc.c
|
||||
cvs.c
|
||||
exc.c
|
||||
exs.c
|
||||
hcc.c
|
||||
hcv.c
|
||||
hv.c
|
||||
hvc.c
|
||||
log2i.c
|
||||
log2p.c
|
||||
sec.c
|
||||
sech.c
|
||||
vcs.c
|
||||
ver.c
|
||||
'
|
||||
LIBCPLEXSRCS='
|
||||
cacos.c
|
||||
cacosh.c
|
||||
casin.c
|
||||
casinh.c
|
||||
catan.c
|
||||
catanh.c
|
||||
ccos.c
|
||||
ccosh.c
|
||||
cexp.c
|
||||
clog.c
|
||||
cpow.c
|
||||
csin.c
|
||||
csinh.c
|
||||
csqrt.c
|
||||
ctan.c
|
||||
ctanh.c
|
||||
'
|
||||
LIBCPLEX2SRCS='
|
||||
cacot.c
|
||||
cacoth.c
|
||||
cacsc.c
|
||||
cacsch.c
|
||||
casec.c
|
||||
casech.c
|
||||
casin.c
|
||||
casinh.c
|
||||
catan.c
|
||||
catanh.c
|
||||
ccbrt.c
|
||||
ccos.c
|
||||
ccosh.c
|
||||
ccot.c
|
||||
ccoth.c
|
||||
ccsc.c
|
||||
ccsch.c
|
||||
cexp.c
|
||||
clog.c
|
||||
clog10.c
|
||||
clogb.c
|
||||
cpow.c
|
||||
clog10.c
|
||||
csec.c
|
||||
csech.c
|
||||
csgn.c
|
||||
csin.c
|
||||
csinh.c
|
||||
csqrt.c
|
||||
ctan.c
|
||||
ctanh.c
|
||||
prim.c
|
||||
'
|
||||
LIBC1SRCS='
|
||||
@@ -383,6 +538,18 @@ utils.c
|
||||
vastubs.c
|
||||
'
|
||||
|
||||
if $dlibm; then
|
||||
LIBREALSRCS="${LIBREAL2SRCS}"
|
||||
else
|
||||
LIBREALSRCS="${LIBREALSRCS}${LIBREAL2SRCS}"
|
||||
fi
|
||||
|
||||
if $dlibm; then
|
||||
LIBCPLEXSRCS="${LIBCPLEX2SRCS}"
|
||||
else
|
||||
LIBCPLEXSRCS="${LIBCPLEXSRCS}${LIBCPLEX2SRCS}"
|
||||
fi
|
||||
|
||||
amathc="amathc"
|
||||
amath="amath"
|
||||
amathcplex="amathcplex"
|
||||
@@ -394,6 +561,9 @@ appstatement="statement"
|
||||
appsystem="appsystem"
|
||||
program="src/main"
|
||||
|
||||
ldsysflags="-l${appsystem} -l${appfunction} -l${appstatement} -l${appmain} -l${appfunction} -l${appstatement} -l${appmain} "
|
||||
ldlibflags="-l${amathapp} ${libm}-l${amathcplex} ${libm}-l${amath} -l${amathc} ${gcclib}"
|
||||
|
||||
############################ Main Application ###########################
|
||||
{
|
||||
echo "CXX = ${crosscompile}${cxxcompiler}"
|
||||
@@ -529,9 +699,11 @@ echo "CXXFLAGS = ${libop}${options} ${cxxflags}-I. -I.. -Wall"
|
||||
echo "AR = ${crosscompile}ar"
|
||||
echo "RANLIB = ${crosscompile}ranlib"
|
||||
echo "MKDIR = mkdir -p"
|
||||
echo "RMDIR = rm -Rf"
|
||||
echo "DEL = rm -f"
|
||||
echo "INSTALL = install -m 0644"
|
||||
echo "LDCONFIG = ldconfig"
|
||||
echo "DOXYGEN = doxygen"
|
||||
echo "PREFIX = ${prefix}"
|
||||
echo "INSTDIR = \${DESTDIR}\${PREFIX}/lib/amath"
|
||||
echo "INSTDIRI = \${DESTDIR}\${PREFIX}/include/amath"
|
||||
@@ -568,12 +740,16 @@ echo " \${MKDIR} static"
|
||||
echo " \${MKDIR} shared"
|
||||
echo
|
||||
echo "\${solib}: build ${files2}"
|
||||
echo " \${CXX} \${CXXFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}.${version} -o \${solib} ${files2}"
|
||||
echo " \${CXX} \${CXXFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}${soverion} -o \${solib} ${files2}"
|
||||
echo
|
||||
echo "\${alib}: build ${files}"
|
||||
echo " \${AR} rcs static/\${alib} ${files}"
|
||||
echo " \${RANLIB} static/\${alib}"
|
||||
echo
|
||||
echo ".PHONY: doc"
|
||||
echo "doc:"
|
||||
echo " \${DOXYGEN} amatha.dox"
|
||||
echo
|
||||
echo ".PHONY: install"
|
||||
echo "install: \${alib} \${solib}"
|
||||
echo " \${MKDIR} \${INSTDIR}"
|
||||
@@ -583,14 +759,18 @@ echo " \${INSTALL} static/\${alib} \${INSTDIR}/\${alib}"
|
||||
echo " \${INSTALL} \${solib} \${INSTDIR}/\${solib}"
|
||||
echo " \${INSTALL} \${pkgconfig} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${INSTALL} aengine.h \${INSTDIRI}/aengine.h"
|
||||
echo " \${INSTALL} bigint.h \${INSTDIRI}/bigint.h"
|
||||
echo " \${INSTALL} charbuf.h \${INSTDIRI}/charbuf.h"
|
||||
echo " \${INSTALL} cplex.h \${INSTDIRI}/cplex.h"
|
||||
echo " \${INSTALL} integer.h \${INSTDIRI}/integer.h"
|
||||
echo " \${INSTALL} nnumb.h \${INSTDIRI}/nnumb.h"
|
||||
echo " \${INSTALL} ntext.h \${INSTDIRI}/ntext.h"
|
||||
echo " \${INSTALL} ntext.h \${INSTDIRI}/ntextd.h"
|
||||
echo " \${INSTALL} ntext.h \${INSTDIRI}/ntextp.h"
|
||||
echo " \${INSTALL} numb.h \${INSTDIRI}/numb.h"
|
||||
echo " \${INSTALL} real.h \${INSTDIRI}/real.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG} \${INSTDIR}"
|
||||
fi
|
||||
echo
|
||||
echo ".PHONY: uninstall"
|
||||
echo "uninstall:"
|
||||
@@ -605,11 +785,19 @@ echo " \${DEL} \${INSTDIRI}/nnumb.h"
|
||||
echo " \${DEL} \${INSTDIRI}/ntext.h"
|
||||
echo " \${DEL} \${INSTDIRI}/numb.h"
|
||||
echo " \${DEL} \${INSTDIRI}/real.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG}"
|
||||
fi
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " \${DEL} static/\${alib} \${solib} ${files} ${files2}"
|
||||
echo
|
||||
echo "very-clean: clean"
|
||||
echo " \${DEL} doxygen.warn"
|
||||
echo " \${RMDIR} man"
|
||||
echo " \${RMDIR} static"
|
||||
echo " \${RMDIR} shared"
|
||||
echo
|
||||
} > src/lib/Makefile
|
||||
#########################################################################
|
||||
|
||||
@@ -620,14 +808,16 @@ echo "CFLAGS = -std=c9x ${libop}${options} ${cflags}-I. -I.. -Wall"
|
||||
echo "AR = ${crosscompile}ar"
|
||||
echo "RANLIB = ${crosscompile}ranlib"
|
||||
echo "MKDIR = mkdir -p"
|
||||
echo "RMDIR = rm -Rf"
|
||||
echo "DEL = rm -f"
|
||||
echo "INSTALL = install -m 0644"
|
||||
echo "LDCONFIG = ldconfig"
|
||||
echo "DOXYGEN = doxygen"
|
||||
echo "PREFIX = ${prefix}"
|
||||
echo "INSTDIR = \${DESTDIR}\${PREFIX}/lib/amath"
|
||||
echo "INSTDIRI = \${DESTDIR}\${PREFIX}/include/amath"
|
||||
echo "INSTDIRPC = \${DESTDIR}\${PREFIX}/${pkgconfigdir}"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/share/man/man3"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/${mandir}/man3"
|
||||
echo "alib = lib${amathc}.a"
|
||||
echo "solib = lib${amathc}.so"
|
||||
echo "pkgconfig = amathc.pc"
|
||||
@@ -661,12 +851,16 @@ echo " \${MKDIR} static"
|
||||
echo " \${MKDIR} shared"
|
||||
echo
|
||||
echo "\${solib}: build ${libcs}"
|
||||
echo " \${CC} \${CFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}.${version} -o \${solib} ${libcs} -lc"
|
||||
echo " \${CC} \${CFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}${soverion} -o \${solib} ${libcs} -lc"
|
||||
echo
|
||||
echo "\${alib}: build ${libc}"
|
||||
echo " \${AR} rcs static/\${alib} ${libc}"
|
||||
echo " \${RANLIB} static/\${alib}"
|
||||
echo
|
||||
echo ".PHONY: doc"
|
||||
echo "doc:"
|
||||
echo " \${DOXYGEN} amathc.dox"
|
||||
echo
|
||||
echo ".PHONY: install"
|
||||
echo "install: \${alib} \${solib}"
|
||||
echo " \${MKDIR} \${INSTDIR}"
|
||||
@@ -678,7 +872,9 @@ echo " \${INSTALL} \${pkgconfig} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${INSTALL} \${manpage} \${INSTDIRM}/\${manpage}"
|
||||
echo " \${INSTALL} ../amath.h \${INSTDIRI}"
|
||||
echo " \${INSTALL} ../amathc.h \${INSTDIRI}"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG} \${INSTDIR}"
|
||||
fi
|
||||
echo
|
||||
echo ".PHONY: uninstall"
|
||||
echo "uninstall:"
|
||||
@@ -688,11 +884,19 @@ echo " \${DEL} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${DEL} \${INSTDIRM}/\${manpage}"
|
||||
echo " \${DEL} \${INSTDIRI}/amath.h"
|
||||
echo " \${DEL} \${INSTDIRI}/amathc.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG}"
|
||||
fi
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " \${DEL} static/\${alib} \${solib} ${libc} ${libcs}"
|
||||
echo
|
||||
echo "very-clean: clean"
|
||||
echo " \${DEL} doxygen.warn"
|
||||
echo " \${RMDIR} man"
|
||||
echo " \${RMDIR} static"
|
||||
echo " \${RMDIR} shared"
|
||||
echo
|
||||
} > src/clib/Makefile
|
||||
#########################################################################
|
||||
|
||||
@@ -703,14 +907,16 @@ echo "CFLAGS = -std=c9x ${libop}${options} ${cflags}-I. -I.. -Wall"
|
||||
echo "AR = ${crosscompile}ar"
|
||||
echo "RANLIB = ${crosscompile}ranlib"
|
||||
echo "MKDIR = mkdir -p"
|
||||
echo "RMDIR = rm -Rf"
|
||||
echo "DEL = rm -f"
|
||||
echo "INSTALL = install -m 0644"
|
||||
echo "LDCONFIG = ldconfig"
|
||||
echo "DOXYGEN = doxygen"
|
||||
echo "PREFIX = ${prefix}"
|
||||
echo "INSTDIR = \${DESTDIR}\${PREFIX}/lib/amath"
|
||||
echo "INSTDIRI = \${DESTDIR}\${PREFIX}/include/amath"
|
||||
echo "INSTDIRPC = \${DESTDIR}\${PREFIX}/${pkgconfigdir}"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/share/man/man3"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/${mandir}/man3"
|
||||
echo "alib = lib${amath}.a"
|
||||
echo "solib = lib${amath}.so"
|
||||
echo "pkgconfig = amathr.pc"
|
||||
@@ -744,12 +950,16 @@ echo " \${MKDIR} static"
|
||||
echo " \${MKDIR} shared"
|
||||
echo
|
||||
echo "\${solib}: build ${libamaths}"
|
||||
echo " \${CC} \${CFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}.${version} -o \${solib} ${libamaths}"
|
||||
echo " \${CC} \${CFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}${soverion} -o \${solib} ${libamaths}"
|
||||
echo
|
||||
echo "\${alib}: build ${libamath}"
|
||||
echo " \${AR} rcs static/\${alib} ${libamath}"
|
||||
echo " \${RANLIB} static/\${alib}"
|
||||
echo
|
||||
echo ".PHONY: doc"
|
||||
echo "doc:"
|
||||
echo " \${DOXYGEN} amathr.dox"
|
||||
echo
|
||||
echo ".PHONY: install"
|
||||
echo "install: \${alib} \${solib}"
|
||||
echo " \${MKDIR} \${INSTDIR}"
|
||||
@@ -759,8 +969,10 @@ echo " \${INSTALL} static/\${alib} \${INSTDIR}/\${alib}"
|
||||
echo " \${INSTALL} \${solib} \${INSTDIR}/\${solib}"
|
||||
echo " \${INSTALL} \${pkgconfig} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${INSTALL} \${manpage} \${INSTDIRM}/\${manpage}"
|
||||
echo " \${INSTALL} ../math.h \${INSTDIRI}/amathr.h"
|
||||
echo " \${INSTALL} ../mathr.h \${INSTDIRI}/mathr.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG} \${INSTDIR}"
|
||||
fi
|
||||
echo
|
||||
echo ".PHONY: uninstall"
|
||||
echo "uninstall:"
|
||||
@@ -768,12 +980,20 @@ echo " \${DEL} \${INSTDIR}/\${alib}"
|
||||
echo " \${DEL} \${INSTDIR}/\${solib}"
|
||||
echo " \${DEL} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${DEL} \${INSTDIRM}/\${manpage}"
|
||||
echo " \${DEL} \${INSTDIRI}/amathr.h"
|
||||
echo " \${DEL} \${INSTDIRI}/mathr.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG}"
|
||||
fi
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " \${DEL} static/\${alib} \${solib} ${libamath} ${libamaths}"
|
||||
echo
|
||||
echo "very-clean: clean"
|
||||
echo " \${DEL} doxygen.warn"
|
||||
echo " \${RMDIR} man"
|
||||
echo " \${RMDIR} static"
|
||||
echo " \${RMDIR} shared"
|
||||
echo
|
||||
} > src/real/Makefile
|
||||
#########################################################################
|
||||
|
||||
@@ -784,14 +1004,16 @@ echo "CFLAGS = -std=c9x ${libop}${options} ${cxxflags}-I. -I.. -Wall"
|
||||
echo "AR = ${crosscompile}ar"
|
||||
echo "RANLIB = ${crosscompile}ranlib"
|
||||
echo "MKDIR = mkdir -p"
|
||||
echo "RMDIR = rm -Rf"
|
||||
echo "DEL = rm -f"
|
||||
echo "INSTALL = install -m 0644"
|
||||
echo "LDCONFIG = ldconfig"
|
||||
echo "DOXYGEN = doxygen"
|
||||
echo "PREFIX = ${prefix}"
|
||||
echo "INSTDIR = \${DESTDIR}\${PREFIX}/lib/amath"
|
||||
echo "INSTDIRI = \${DESTDIR}\${PREFIX}/include/amath"
|
||||
echo "INSTDIRPC = \${DESTDIR}\${PREFIX}/${pkgconfigdir}"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/share/man/man3"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/${mandir}/man3"
|
||||
echo "alib = lib${amathcplex}.a"
|
||||
echo "solib = lib${amathcplex}.so"
|
||||
echo "pkgconfig = amathi.pc"
|
||||
@@ -825,12 +1047,16 @@ echo " \${MKDIR} static"
|
||||
echo " \${MKDIR} shared"
|
||||
echo
|
||||
echo "\${solib}: build ${libcomplexs}"
|
||||
echo " \${CC} \${CFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}.${version} -o \${solib} ${libcomplexs}"
|
||||
echo " \${CC} \${CFLAGS} -shared ${exestrip} -fPIC -Wl,-soname,\${solib}${soverion} -o \${solib} ${libcomplexs}"
|
||||
echo
|
||||
echo "\${alib}: build ${libcomplex}"
|
||||
echo " \${AR} rcs static/\${alib} ${libcomplex}"
|
||||
echo " \${RANLIB} static/\${alib}"
|
||||
echo
|
||||
echo ".PHONY: doc"
|
||||
echo "doc:"
|
||||
echo " \${DOXYGEN} amathi.dox"
|
||||
echo
|
||||
echo ".PHONY: install"
|
||||
echo "install: \${alib} \${solib}"
|
||||
echo " \${MKDIR} \${INSTDIR}"
|
||||
@@ -840,8 +1066,10 @@ echo " \${INSTALL} static/\${alib} \${INSTDIR}/\${alib}"
|
||||
echo " \${INSTALL} \${solib} \${INSTDIR}/\${solib}"
|
||||
echo " \${INSTALL} \${pkgconfig} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${INSTALL} \${manpage} \${INSTDIRM}/\${manpage}"
|
||||
echo " \${INSTALL} ../complex.h \${INSTDIRI}/amathi.h"
|
||||
echo " \${INSTALL} ../mathi.h \${INSTDIRI}/mathi.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG} \${INSTDIR}"
|
||||
fi
|
||||
echo
|
||||
echo ".PHONY: uninstall"
|
||||
echo "uninstall:"
|
||||
@@ -850,12 +1078,20 @@ echo " \${DEL} \${INSTDIR}/\${solib}"
|
||||
echo " \${DEL} \${INSTDIRPC}/\${pkgconfig}"
|
||||
echo " \${DEL} \${INSTDIRM}/\${manpage}"
|
||||
echo " \${DEL} \${INSTDIRPC}/amathi.pc"
|
||||
echo " \${DEL} \${INSTDIRI}/amathi.h"
|
||||
echo " \${DEL} \${INSTDIRI}/mathi.h"
|
||||
if ${useldconfig}; then
|
||||
echo " \${LDCONFIG}"
|
||||
fi
|
||||
echo
|
||||
echo "clean:"
|
||||
echo " \${DEL} static/\${alib} \${solib} ${libcomplex} ${libcomplexs}"
|
||||
echo
|
||||
echo "very-clean: clean"
|
||||
echo " \${DEL} doxygen.warn"
|
||||
echo " \${RMDIR} man"
|
||||
echo " \${RMDIR} static"
|
||||
echo " \${RMDIR} shared"
|
||||
echo
|
||||
} > src/cplex/Makefile
|
||||
#########################################################################
|
||||
|
||||
@@ -868,7 +1104,7 @@ echo "CFLAGS = ${appop}${options} ${cflags}-Wall -Isrc -Isrc/main"
|
||||
echo "CXXFLAGS = ${appop}${options} ${cxxflags}-Wall -Isrc -Isrc/main"
|
||||
echo "AR = ${crosscompile}ar"
|
||||
echo "RANLIB = ${crosscompile}ranlib"
|
||||
echo "LFLAGS = ${ldflags}-l${appsystem} -l${appfunction} -l${appstatement} -l${appmain} -l${appfunction} -l${appstatement} -l${appmain} -l${amathapp} -l${amathcplex} -l${amath} -l${amathc} ${gcclib}"
|
||||
echo "LFLAGS = ${ldflags}${ldsysflags}${ldlibflags}"
|
||||
echo "LPATH = -Lsrc/lib -Lsrc/clib -Lsrc/real -Lsrc/cplex -Lsrc/main/function -Lsrc/main/statement -Lsrc/main -Lsrc/system"
|
||||
echo "LPATHS = -Lsrc/lib/static -Lsrc/clib/static -Lsrc/real/static -Lsrc/cplex/static -Lsrc/main/function -Lsrc/main/statement -Lsrc/main -Lsrc/system"
|
||||
echo "FLXCAT = build/flexcat/flexcat"
|
||||
@@ -878,15 +1114,14 @@ echo "INSTALLP = install -m 0755"
|
||||
echo "INSTALLM = install -m 0644"
|
||||
echo "PREFIX = ${prefix}"
|
||||
echo "INSTDIRP = \${DESTDIR}\${PREFIX}/bin"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/share/man/man1"
|
||||
echo "INSTDIRM = \${DESTDIR}\${PREFIX}/${mandir}/man1"
|
||||
echo
|
||||
echo "all: shared-app"
|
||||
echo "all: shared-libs static-libs static-app"
|
||||
echo "amath: shared-libs static-libs shared-app"
|
||||
echo "static: static-app"
|
||||
echo "app: ${appmain} ${appfunction} ${appstatement} ${appsystem}"
|
||||
echo "libs: ${amathapp} ${amath} ${amathc} ${amathcplex}"
|
||||
echo
|
||||
echo "amath: static-app"
|
||||
echo "static: static-app"
|
||||
echo
|
||||
echo "${program}.o: ${program}.cpp"
|
||||
echo " \${CXX} \${CXXFLAGS} -c ${program}.cpp -o ${program}.o"
|
||||
echo
|
||||
@@ -914,12 +1149,17 @@ echo
|
||||
echo "${amathcplex}:"
|
||||
echo " cd src/cplex && \${MAKE}"
|
||||
echo
|
||||
echo "localize:"
|
||||
echo "locale:"
|
||||
echo " cd build/flexcat && \${MAKE}"
|
||||
echo " \${FLXCAT} text/keyword.cd src/localize/kword.h=text/keyword.sd"
|
||||
echo " \${FLXCAT} text/help.cd src/localize/help.h=text/help.sd"
|
||||
echo " \${FLXCAT} text/ident.cd src/localize/ident.h=text/ident.sd"
|
||||
echo " \${FLXCAT} text/text.cd src/localize/text.h=text/text.sd"
|
||||
echo " \${FLXCAT} text/keyword.cd src/loc/kword.h=text/keyword.sd"
|
||||
echo " \${FLXCAT} text/help.cd src/loc/help.h=text/help.sd"
|
||||
echo " \${FLXCAT} text/ident.cd src/loc/ident.h=text/ident.sd"
|
||||
echo " \${FLXCAT} text/text.cd src/loc/text.h=text/text.sd"
|
||||
echo
|
||||
echo "doc:"
|
||||
echo " cd src/clib && \${MAKE} doc"
|
||||
echo " cd src/real && \${MAKE} doc"
|
||||
echo " cd src/cplex && \${MAKE} doc"
|
||||
echo
|
||||
echo "catalogs:"
|
||||
echo " cd build/flexcat && \${MAKE}"
|
||||
@@ -928,18 +1168,22 @@ echo " \${FLXCAT} text/help.cd catalog/english/amath-help.ct CATALOG dist/catalo
|
||||
echo " \${FLXCAT} text/ident.cd catalog/english/amath-ident.ct CATALOG dist/catalog/english/amath-ident.catalog"
|
||||
echo " \${FLXCAT} text/text.cd catalog/english/amath-text.ct CATALOG dist/catalog/english/amath-text.catalog"
|
||||
echo
|
||||
echo "shared-app: app libs ${program}.o"
|
||||
echo " \${CC} \${CFLAGS} ${exestrip} ${program}.o -o amath \${LPATH} \${LFLAGS}"
|
||||
echo "shared-libs:"
|
||||
echo " cd src/lib && \${MAKE} shared"
|
||||
echo " cd src/clib && \${MAKE} shared"
|
||||
echo " cd src/real && \${MAKE} shared"
|
||||
echo " cd src/cplex && \${MAKE} shared"
|
||||
echo
|
||||
echo "static-app: ${program}.o"
|
||||
echo "static-libs:"
|
||||
echo " cd src/lib && \${MAKE} static"
|
||||
echo " cd src/clib && \${MAKE} static"
|
||||
echo " cd src/real && \${MAKE} static"
|
||||
echo " cd src/cplex && \${MAKE} static"
|
||||
echo " cd src/main && \${MAKE} static"
|
||||
echo " cd src/system && \${MAKE} static"
|
||||
echo " cd src/main/function && \${MAKE} static"
|
||||
echo " cd src/main/statement && \${MAKE} static"
|
||||
echo
|
||||
echo "shared-app: app shared-libs ${program}.o"
|
||||
echo " \${CC} \${CFLAGS} ${exestrip} ${program}.o -o amath \${LPATH} \${LFLAGS}"
|
||||
echo
|
||||
echo "static-app: app static-libs ${program}.o"
|
||||
echo " \${CC} \${CFLAGS} ${exestrip} ${program}.o -o amath \${LPATHS} \${LFLAGS}"
|
||||
echo
|
||||
echo ".PHONY: test"
|
||||
@@ -948,7 +1192,7 @@ echo " LD_LIBRARY_PATH=src/clib/:src/lib:src/cplex:scr/real"
|
||||
echo " ./amath test"
|
||||
echo
|
||||
echo ".PHONY: install"
|
||||
echo "install: shared-app"
|
||||
echo "install:"
|
||||
echo " cd src/lib && \${MAKE} install"
|
||||
echo " cd src/clib && \${MAKE} install"
|
||||
echo " cd src/real && \${MAKE} install"
|
||||
@@ -978,6 +1222,13 @@ echo " cd src/main/statement && \${MAKE} clean"
|
||||
echo " cd build/flexcat && \${MAKE} clean"
|
||||
echo " \${DEL} ${program}.o amath"
|
||||
echo
|
||||
echo ".PHONY: very-clean"
|
||||
echo "very-clean: clean"
|
||||
echo " cd src/lib && \${MAKE} very-clean"
|
||||
echo " cd src/clib && \${MAKE} very-clean"
|
||||
echo " cd src/real && \${MAKE} very-clean"
|
||||
echo " cd src/cplex && \${MAKE} very-clean"
|
||||
echo
|
||||
} > Makefile
|
||||
#########################################################################
|
||||
|
||||
|
||||
+24
-17
@@ -60,7 +60,13 @@
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef _WIN32
|
||||
#ifdef __APPLE__
|
||||
# ifndef APPLE
|
||||
# define APPLE
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
# ifndef WINDOWS
|
||||
# define WINDOWS
|
||||
# endif
|
||||
@@ -78,7 +84,7 @@
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#if defined(HAIKU) || defined(UNIX)
|
||||
#if defined(HAIKU) || defined(UNIX) || defined(APPLE) || defined(_POSIX_VERSION)
|
||||
# ifndef POSIX
|
||||
# define POSIX
|
||||
# endif
|
||||
@@ -110,16 +116,22 @@ typedef u_int32_t uint32_t;
|
||||
typedef u_int64_t uint64_t;
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#if defined(AROS) || defined(MORPHOS) || defined(AOS4)
|
||||
#if defined(AROS) || defined(MORPHOS) || defined(AOS4) || defined(APPLE)
|
||||
# include <stdint.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#if (__cplusplus <= 199711L && !defined(WINDOWS)) || !defined(__cplusplus)
|
||||
#define nullptr 0
|
||||
#elif (__cplusplus <= 199711L) && (defined(__GNUC__) || defined(__GNUG__))
|
||||
#ifndef nullptr
|
||||
#define nullptr 0
|
||||
#endif
|
||||
#elif (__cplusplus <= 199711L) && (defined(__GNUC__) || defined(__GNUG__))
|
||||
#ifndef nullptr
|
||||
#define nullptr 0
|
||||
#endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#define assert(x)
|
||||
/******************************************************************************/
|
||||
/* Compilers*/
|
||||
#if defined(__clang__)
|
||||
@@ -212,8 +224,10 @@ typedef u_int64_t uint64_t;
|
||||
#define SPACE " "
|
||||
#define DOT "."
|
||||
/******************************************************************************/
|
||||
#ifdef WINDOWS
|
||||
#if defined(WINDOWS)
|
||||
#define NEWLINE "\r\n"
|
||||
#elif defined(APPLE)
|
||||
#define NEWLINE "\r"
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
@@ -276,22 +290,15 @@ typedef int bool;
|
||||
# define TXTFPU EMPTYSTRING
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#if defined(WITHTEST)
|
||||
# define TXTOPTMSG SPACE "(test)"
|
||||
#else
|
||||
# define TXTOPTMSG EMPTYSTRING
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#define TXTARCH TXTCPU TXTFPU
|
||||
#define RELDATESTAMP "(10-04-2017)"
|
||||
#define TXTDOSVERSION "\0$VER: amath 1.71" SPACE RELDATESTAMP SPACE TXTARCH
|
||||
#define TXTTITLE "amath version 1.7.1"
|
||||
#define RELDATESTAMP "(13-04-2017)"
|
||||
#define TXTDOSVERSION "\0$VER: amath 1.80" SPACE RELDATESTAMP SPACE TXTARCH
|
||||
#define TXTTITLE "amath version 1.8.0"
|
||||
#define TXTCOPYRIGHT "(c) 2017 Carsten Sonne Larsen"
|
||||
#define TXTSTARTMSG TXTTITLE SPACE TXTCOPYRIGHT
|
||||
/******************************************************************************/
|
||||
#define TXTVERSMSG TXTTITLE SPACE RELDATESTAMP SPACE TXTARCH
|
||||
#define TXTCOMPMSG "Compiled with " COMP_NAME SPACE COMP_VERS TXTOPTMSG
|
||||
#define TXTCOMPSHTMSG "Compiled with " COMP_NAME SPACE COMP_VERS
|
||||
#define TXTCOMPMSG "Compiled with " COMP_NAME SPACE COMP_VERS
|
||||
/******************************************************************************/
|
||||
#define CPROCNAME "amath_console"
|
||||
/******************************************************************************/
|
||||
|
||||
+1
-3
@@ -32,8 +32,7 @@
|
||||
|
||||
/**
|
||||
* @file amathc.h
|
||||
* @brief C functions for manipulating strings and memory.
|
||||
*
|
||||
* @brief C functions for manipulating strings and memory
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
@@ -54,7 +53,6 @@ void FreeMemSafe(void*);
|
||||
void DetachMemSafe(void*);
|
||||
void FreeAllSafe();
|
||||
void MemUsage(long*, long*, long*);
|
||||
|
||||
int StrLen(const char* string);
|
||||
bool StrIsEqual(const char* s1, const char* s2);
|
||||
void MemSet(void* destination, int c0, unsigned int length);
|
||||
|
||||
+217
-241
@@ -1,26 +1,39 @@
|
||||
.TH "amath/amathc.h" 3 "Wed Mar 1 2017" "Version 1.7.1" "amath" \" -*- nroff -*-
|
||||
.ad l
|
||||
.nh
|
||||
.\" Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. 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.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
.TH "amathc.h" 3 "Version 1.8.0" "April 13 2017"
|
||||
.SH NAME
|
||||
amathc.h \- C functions for manipulating strings and memory
|
||||
|
||||
.SH SYNOPSIS
|
||||
.br
|
||||
.PP
|
||||
\fC#include <stddef\&.h>\fP
|
||||
.br
|
||||
\fC#include 'amath\&.h'\fP
|
||||
.br
|
||||
|
||||
.SS "Classes"
|
||||
|
||||
\fC#include \fB"amathc\&.h"\fP
|
||||
.SS "Data Structures"
|
||||
.in +1c
|
||||
.ti -1c
|
||||
.RI "struct \fBtexttag\fP"
|
||||
.br
|
||||
.in -1c
|
||||
.SS "Functions"
|
||||
|
||||
.in +1c
|
||||
.ti -1c
|
||||
.RI "void * \fBAllocMemSafe\fP (size_t)"
|
||||
@@ -31,6 +44,10 @@ amathc.h \- C functions for manipulating strings and memory
|
||||
.br
|
||||
.RI "\fIDeallocate memory from the global memory list\&. \fP"
|
||||
.ti -1c
|
||||
.RI "void \fBDetachMemSafe\fP (void *)"
|
||||
.br
|
||||
.RI "\fIDetach an allocated memory from the global memory list\&. \fP"
|
||||
.ti -1c
|
||||
.RI "void \fBFreeAllSafe\fP ()"
|
||||
.br
|
||||
.RI "\fIDeallocate all memory in the global memory list\&. \fP"
|
||||
@@ -43,7 +60,7 @@ amathc.h \- C functions for manipulating strings and memory
|
||||
.br
|
||||
.RI "\fIGet the length of a null terminated string\&. \fP"
|
||||
.ti -1c
|
||||
.RI "\fBbool\fP \fBStrIsEqual\fP (const char *s1, const char *s2)"
|
||||
.RI "bool \fBStrIsEqual\fP (const char *s1, const char *s2)"
|
||||
.br
|
||||
.RI "\fICompare two null terminated strings to each other\&. \fP"
|
||||
.ti -1c
|
||||
@@ -61,21 +78,11 @@ amathc.h \- C functions for manipulating strings and memory
|
||||
.ti -1c
|
||||
.RI "void \fBUntag\fP (char *destination, const char *source, \fBtexttag\fP tags[], unsigned int tagcount)"
|
||||
.br
|
||||
.in -1c
|
||||
.SH "Detailed Description"
|
||||
.PP
|
||||
C functions for manipulating strings and memory\&.
|
||||
|
||||
|
||||
.PP
|
||||
Definition in file \fBamathc\&.h\fP\&.
|
||||
.SH "Function Documentation"
|
||||
.br
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
.SS "unsigned int AllocAndCopy (char ** destination, const char * source)"
|
||||
.br
|
||||
.PP
|
||||
Allocate memory and copy a string into the array\&.
|
||||
Allocate memory and copy a string into the array\&.
|
||||
.PP
|
||||
Definition at line 40 of file alloccpy\&.c\&.
|
||||
.PP
|
||||
@@ -107,7 +114,6 @@ Definition at line 40 of file alloccpy\&.c\&.
|
||||
69 }
|
||||
.fi
|
||||
.SS "void* AllocMemSafe (size_t)"
|
||||
|
||||
.PP
|
||||
Allocate memory and add it to the global memory list\&.
|
||||
.PP
|
||||
@@ -171,251 +177,211 @@ Definition at line 86 of file mem\&.c\&.
|
||||
141 return newblock->address;
|
||||
142 }
|
||||
.fi
|
||||
.SS "void DetachMemSafe (void * block)"
|
||||
.PP
|
||||
Detach an allocated memory from the global memory list\&. The memory block is only detached, not deallocated\&.
|
||||
.PP
|
||||
Definition at line 209 of file mem\&.c\&.
|
||||
.PP
|
||||
.nf
|
||||
210 {
|
||||
211 RemoveMemSafe(block, false);
|
||||
212 }
|
||||
.fi
|
||||
.SS "void FreeAllSafe ()"
|
||||
|
||||
.PP
|
||||
Deallocate all memory in the global memory list\&.
|
||||
.PP
|
||||
Definition at line 199 of file mem\&.c\&.
|
||||
Definition at line 217 of file mem\&.c\&.
|
||||
.PP
|
||||
.nf
|
||||
200 {
|
||||
201 struct MemoryBlock *current, *next;
|
||||
202
|
||||
203 if (list == nullptr)
|
||||
204 {
|
||||
205 return;
|
||||
206 }
|
||||
207
|
||||
208 current = list->first;
|
||||
209 while (current != nullptr)
|
||||
210 {
|
||||
211 next = current->next;
|
||||
212 FREE_MEM(current->address);
|
||||
213 FREE_MEM(current);
|
||||
214 current = next;
|
||||
215 }
|
||||
216
|
||||
217 FREE_MEM(list);
|
||||
218 list = nullptr;
|
||||
219 }
|
||||
218 {
|
||||
219 struct MemoryBlock *current, *next;
|
||||
220
|
||||
221 if (list == nullptr)
|
||||
222 {
|
||||
223 return;
|
||||
224 }
|
||||
225
|
||||
226 current = list->first;
|
||||
227 while (current != nullptr)
|
||||
228 {
|
||||
229 next = current->next;
|
||||
230 FREE_MEM(current->address);
|
||||
231 FREE_MEM(current);
|
||||
232 current = next;
|
||||
233 }
|
||||
234
|
||||
235 FREE_MEM(list);
|
||||
236 list = nullptr;
|
||||
237 }
|
||||
.fi
|
||||
.SS "void FreeMemSafe (void *)"
|
||||
|
||||
.PP
|
||||
Deallocate memory from the global memory list\&.
|
||||
.PP
|
||||
Definition at line 147 of file mem\&.c\&.
|
||||
Definition at line 200 of file mem\&.c\&.
|
||||
.PP
|
||||
.nf
|
||||
148 {
|
||||
149 struct MemoryBlock *current, *previous;
|
||||
150
|
||||
151 if (list == nullptr || block == nullptr)
|
||||
152 {
|
||||
153 dealloc_error("list", 0);
|
||||
154 return;
|
||||
155 }
|
||||
156
|
||||
157 if (block == nullptr)
|
||||
158 {
|
||||
159 dealloc_error("memory", 0);
|
||||
160 return;
|
||||
161 }
|
||||
162
|
||||
163 previous = nullptr;
|
||||
164 current = list->first;
|
||||
165 while (current != nullptr && current->address != block)
|
||||
166 {
|
||||
167 previous = current;
|
||||
168 current = current->next;
|
||||
169 }
|
||||
170
|
||||
171 if (current == nullptr)
|
||||
172 {
|
||||
173 dealloc_error("address not found", block);
|
||||
174 return;
|
||||
175 }
|
||||
176
|
||||
177 if (previous == nullptr)
|
||||
178 {
|
||||
179 list->first = current->next;
|
||||
180 }
|
||||
181 else
|
||||
182 {
|
||||
183 previous->next = current->next;
|
||||
184 }
|
||||
185
|
||||
186 list->size -= current->size;
|
||||
187 list->count--;
|
||||
188
|
||||
189 FREE_MEM(current->address);
|
||||
190 current->address = nullptr;
|
||||
191 current->next = nullptr;
|
||||
192 current->size = 0;
|
||||
193 FREE_MEM(current);
|
||||
194 }
|
||||
201 {
|
||||
202 RemoveMemSafe(block, true);
|
||||
203 }
|
||||
.fi
|
||||
.SS "void MemCopy (void * destination, const void * source, unsigned int length)"
|
||||
|
||||
.PP
|
||||
Copy a block of memory, handling overlap\&.
|
||||
.PP
|
||||
Definition at line 77 of file memcpy\&.c\&.
|
||||
Definition at line 75 of file memcpy\&.c\&.
|
||||
.PP
|
||||
.nf
|
||||
78 {
|
||||
79 char* dst = (char*) destination;
|
||||
80 const char* src = (const char*) source;
|
||||
81 unsigned int t;
|
||||
82
|
||||
83 if (length == 0 || dst == src) // nothing to do
|
||||
84 return;
|
||||
85
|
||||
86 if ((mem_ptr)dst < (mem_ptr)src)
|
||||
87 {
|
||||
88 // Copy forward
|
||||
92 t = (mem_ptr)src; // only need low bits
|
||||
93 if ((t | (mem_ptr)dst) & wmask)
|
||||
94 {
|
||||
95 // Try to align operands\&. This cannot be done unless the low bits match\&.
|
||||
96 if ((t ^ (mem_ptr)dst) & wmask || length < wsize)
|
||||
97 t = length;
|
||||
98 else
|
||||
99 t = wsize - (t & wmask);
|
||||
100 length -= t;
|
||||
101
|
||||
102 TLOOP1(*dst++ = *src++);
|
||||
103 }
|
||||
104
|
||||
105 // Copy whole words, then mop up any trailing bytes\&.
|
||||
106 t = length / wsize;
|
||||
107 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
|
||||
108
|
||||
109 t = length & wmask;
|
||||
110 TLOOP(*dst++ = *src++);
|
||||
111 #endif
|
||||
112 }
|
||||
113 else
|
||||
114 {
|
||||
115 // Copy backwards\&. Otherwise essentially the same\&.
|
||||
116 // Alignment works as before, except that it takes
|
||||
117 // (t&wmask) bytes to align, not wsize-(t&wmask)\&.
|
||||
118 src += length;
|
||||
119 dst += length;
|
||||
120 t = (mem_ptr)src;
|
||||
121 if ((t | (mem_ptr)dst) & wmask)
|
||||
122 {
|
||||
123 if ((t ^ (mem_ptr)dst) & wmask || length <= wsize)
|
||||
124 t = length;
|
||||
125 else
|
||||
126 t &= wmask;
|
||||
127 length -= t;
|
||||
128
|
||||
129 TLOOP1(*--dst = *--src);
|
||||
130 }
|
||||
131
|
||||
132 t = length / wsize;
|
||||
133 TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
|
||||
134
|
||||
135 t = length & wmask;
|
||||
136 TLOOP(*--dst = *--src);
|
||||
137 }
|
||||
138 }
|
||||
76 {
|
||||
77 char* dst = (char*) destination;
|
||||
78 const char* src = (const char*) source;
|
||||
79 unsigned int t;
|
||||
80
|
||||
81 if (length == 0 || dst == src) // nothing to do
|
||||
82 return;
|
||||
83
|
||||
84 if ((mem_ptr)dst < (mem_ptr)src)
|
||||
85 {
|
||||
86 // Copy forward
|
||||
90 t = (mem_ptr)src; // only need low bits
|
||||
91 if ((t | (mem_ptr)dst) & wmask)
|
||||
92 {
|
||||
93 // Try to align operands\&. This cannot be done unless the low bits match\&.
|
||||
94 if ((t ^ (mem_ptr)dst) & wmask || length < wsize)
|
||||
95 t = length;
|
||||
96 else
|
||||
97 t = wsize - (t & wmask);
|
||||
98 length -= t;
|
||||
99
|
||||
100 TLOOP1(*dst++ = *src++);
|
||||
101 }
|
||||
102
|
||||
103 // Copy whole words, then mop up any trailing bytes\&.
|
||||
104 t = length / wsize;
|
||||
105 TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
|
||||
106
|
||||
107 t = length & wmask;
|
||||
108 TLOOP(*dst++ = *src++);
|
||||
110 }
|
||||
111 else
|
||||
112 {
|
||||
113 // Copy backwards\&. Otherwise essentially the same\&.
|
||||
114 // Alignment works as before, except that it takes
|
||||
115 // (t&wmask) bytes to align, not wsize-(t&wmask)\&.
|
||||
116 src += length;
|
||||
117 dst += length;
|
||||
118 t = (mem_ptr)src;
|
||||
119 if ((t | (mem_ptr)dst) & wmask)
|
||||
120 {
|
||||
121 if ((t ^ (mem_ptr)dst) & wmask || length <= wsize)
|
||||
122 t = length;
|
||||
123 else
|
||||
124 t &= wmask;
|
||||
125 length -= t;
|
||||
126
|
||||
127 TLOOP1(*--dst = *--src);
|
||||
128 }
|
||||
129
|
||||
130 t = length / wsize;
|
||||
131 TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
|
||||
132
|
||||
133 t = length & wmask;
|
||||
134 TLOOP(*--dst = *--src);
|
||||
135 }
|
||||
136 }
|
||||
.fi
|
||||
.SS "void MemSet (void * destination, int c0, unsigned int length)"
|
||||
|
||||
.PP
|
||||
Fill block of memory with a constant value\&.
|
||||
.PP
|
||||
Definition at line 60 of file memset\&.c\&.
|
||||
Definition at line 56 of file memset\&.c\&.
|
||||
.PP
|
||||
.nf
|
||||
61 {
|
||||
62 unsigned char* dst = (unsigned char*) dst0;
|
||||
63 unsigned int t;
|
||||
64 unsigned int c;
|
||||
65
|
||||
66 /*
|
||||
67 * If not enough words, just fill bytes\&. A length >= 2 words
|
||||
68 * guarantees that at least one of them is `complete' after
|
||||
69 * any necessary alignment\&. For instance:
|
||||
70 *
|
||||
71 * |-----------|-----------|-----------|
|
||||
72 * |00|01|02|03|04|05|06|07|08|09|0A|00|
|
||||
73 * ^---------------------^
|
||||
74 * dst dst+length-1
|
||||
75 *
|
||||
76 * but we use a minimum of 3 here since the overhead of the code
|
||||
77 * to do word writes is substantial\&.
|
||||
78 */
|
||||
79 if (length < 3 * wsize)
|
||||
80 {
|
||||
81 while (length != 0)
|
||||
82 {
|
||||
83 *dst++ = c0;
|
||||
84 --length;
|
||||
85 }
|
||||
86 }
|
||||
87
|
||||
88 if ((c = (unsigned char)c0) != 0)
|
||||
89 { /* Fill the word\&. */
|
||||
90 c = (c << 8) | c; /* u_int is 16 bits\&. */
|
||||
91 #if UINT_MAX > 0xffff
|
||||
92 c = (c << 16) | c; /* u_int is 32 bits\&. */
|
||||
93 #endif
|
||||
94 #if UINT_MAX > 0xffffffff
|
||||
95 c = (c << 32) | c; /* u_int is 64 bits\&. */
|
||||
96 #endif
|
||||
97 }
|
||||
98
|
||||
99 /* Align destination by filling in bytes\&. */
|
||||
100 if ((t = (mem_ptr)dst & wmask) != 0)
|
||||
101 {
|
||||
102 t = wsize - t;
|
||||
103 length -= t;
|
||||
104 do
|
||||
105 {
|
||||
106 *dst++ = c0;
|
||||
107 }
|
||||
108 while (--t != 0);
|
||||
109 }
|
||||
110
|
||||
111 /* Fill words\&. Length was >= 2*words so we know t >= 1 here\&. */
|
||||
112 t = length / wsize;
|
||||
113 do
|
||||
114 {
|
||||
115 *(unsigned int*)dst = c;
|
||||
116 dst += wsize;
|
||||
117 }
|
||||
118 while (--t != 0);
|
||||
119
|
||||
120 /* Mop up trailing bytes, if any\&. */
|
||||
121 t = length & wmask;
|
||||
122 if (t != 0)
|
||||
123 do
|
||||
124 {
|
||||
125 *dst++ = c0;
|
||||
126 }
|
||||
127 while (--t != 0);
|
||||
128 }
|
||||
57 {
|
||||
58 unsigned char* dst = (unsigned char*) dst0;
|
||||
59 unsigned int t;
|
||||
60 unsigned int c;
|
||||
61
|
||||
62 /*
|
||||
63 * If not enough words, just fill bytes\&. A length >= 2 words
|
||||
64 * guarantees that at least one of them is `complete' after
|
||||
65 * any necessary alignment\&. For instance:
|
||||
66 *
|
||||
67 * |-----------|-----------|-----------|
|
||||
68 * |00|01|02|03|04|05|06|07|08|09|0A|00|
|
||||
69 * ^---------------------^
|
||||
70 * dst dst+length-1
|
||||
71 *
|
||||
72 * but we use a minimum of 3 here since the overhead of the code
|
||||
73 * to do word writes is substantial\&.
|
||||
74 */
|
||||
75 if (length < 3 * wsize)
|
||||
76 {
|
||||
77 while (length != 0)
|
||||
78 {
|
||||
79 *dst++ = c0;
|
||||
80 --length;
|
||||
81 }
|
||||
82 }
|
||||
83
|
||||
84 if ((c = (unsigned char)c0) != 0)
|
||||
85 { /* Fill the word\&. */
|
||||
86 c = (c << 8) | c; /* u_int is 16 bits\&. */
|
||||
87 #if UINT_MAX > 0xffff
|
||||
88 c = (c << 16) | c; /* u_int is 32 bits\&. */
|
||||
89 #endif
|
||||
90 #if UINT_MAX > 0xffffffff
|
||||
91 c = (c << 32) | c; /* u_int is 64 bits\&. */
|
||||
92 #endif
|
||||
93 }
|
||||
94
|
||||
95 /* Align destination by filling in bytes\&. */
|
||||
96 if ((t = (mem_ptr)dst & wmask) != 0)
|
||||
97 {
|
||||
98 t = wsize - t;
|
||||
99 length -= t;
|
||||
100 do
|
||||
101 {
|
||||
102 *dst++ = c0;
|
||||
103 }
|
||||
104 while (--t != 0);
|
||||
105 }
|
||||
106
|
||||
107 /* Fill words\&. Length was >= 2*words so we know t >= 1 here\&. */
|
||||
108 t = length / wsize;
|
||||
109 do
|
||||
110 {
|
||||
111 *(unsigned int*)dst = c;
|
||||
112 dst += wsize;
|
||||
113 }
|
||||
114 while (--t != 0);
|
||||
115
|
||||
116 /* Mop up trailing bytes, if any\&. */
|
||||
117 t = length & wmask;
|
||||
118 if (t != 0)
|
||||
119 do
|
||||
120 {
|
||||
121 *dst++ = c0;
|
||||
122 }
|
||||
123 while (--t != 0);
|
||||
124 }
|
||||
.fi
|
||||
.SS "void MemUsage (long *, long *, long *)"
|
||||
|
||||
.PP
|
||||
Get memory usage in the global memory list\&.
|
||||
.PP
|
||||
Definition at line 224 of file mem\&.c\&.
|
||||
Definition at line 242 of file mem\&.c\&.
|
||||
.PP
|
||||
.nf
|
||||
225 {
|
||||
226 *blocks = list->count;
|
||||
227 *size = (long)list->size;
|
||||
228 *peak = (long)list->peak;;
|
||||
229 }
|
||||
243 {
|
||||
244 *blocks = list->count;
|
||||
245 *size = (long)list->size;
|
||||
246 *peak = (long)list->peak;;
|
||||
247 }
|
||||
.fi
|
||||
.SS "\fBbool\fP StrIsEqual (const char * s1, const char * s2)"
|
||||
|
||||
.SS "bool StrIsEqual (const char * s1, const char * s2)"
|
||||
.PP
|
||||
Compare two null terminated strings to each other\&.
|
||||
.PP
|
||||
@@ -435,7 +401,6 @@ Definition at line 50 of file strcmp\&.c\&.
|
||||
61 }
|
||||
.fi
|
||||
.SS "int StrLen (const char * string)"
|
||||
|
||||
.PP
|
||||
Get the length of a null terminated string\&.
|
||||
.PP
|
||||
@@ -451,7 +416,6 @@ Definition at line 34 of file strlen\&.c\&.
|
||||
41 }
|
||||
.fi
|
||||
.SS "void Untag (char * destination, const char * source, \fBtexttag\fP tags[], unsigned int tagcount)"
|
||||
|
||||
.PP
|
||||
Definition at line 32 of file untag\&.c\&.
|
||||
.PP
|
||||
@@ -507,6 +471,18 @@ Definition at line 32 of file untag\&.c\&.
|
||||
81 *dest = '\0';
|
||||
82 }
|
||||
.fi
|
||||
.SH "See also"
|
||||
.PP
|
||||
amath(1), amathr(3), amathi(3)
|
||||
.SH HOMEPAGE
|
||||
http://amath.innolan.net/
|
||||
.SH AUTHORS
|
||||
.PP
|
||||
Written by Carsten Sonne Larsen <cs@innolan.net>. The code in MemSet and
|
||||
MemCopy is derived from software contributed to Berkeley by Mike Hibler and
|
||||
Chris Torek.
|
||||
.SH COPYRIGHT
|
||||
Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
.br
|
||||
Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
.br
|
||||
Copyright (c) 1990, 1993 The Regents of the University of California
|
||||
.SH SEE ALSO
|
||||
amath(1), amathr(3), amathi(3)
|
||||
@@ -0,0 +1,154 @@
|
||||
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = "amathc"
|
||||
PROJECT_NUMBER = "1.8.0"
|
||||
PROJECT_BRIEF = "C functions for manipulating strings and memory"
|
||||
PROJECT_LOGO =
|
||||
OUTPUT_DIRECTORY =
|
||||
CREATE_SUBDIRS = NO
|
||||
ALLOW_UNICODE_NAMES = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF =
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = NO
|
||||
STRIP_FROM_PATH =
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
QT_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
INHERIT_DOCS = YES
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 4
|
||||
ALIASES =
|
||||
TCL_SUBST =
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
OPTIMIZE_FOR_FORTRAN = NO
|
||||
OPTIMIZE_OUTPUT_VHDL = NO
|
||||
EXTENSION_MAPPING = C
|
||||
MARKDOWN_SUPPORT = YES
|
||||
AUTOLINK_SUPPORT = YES
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
CPP_CLI_SUPPORT = NO
|
||||
SIP_SUPPORT = NO
|
||||
IDL_PROPERTY_SUPPORT = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
GROUP_NESTED_COMPOUNDS = NO
|
||||
SUBGROUPING = YES
|
||||
INLINE_GROUPED_CLASSES = NO
|
||||
INLINE_SIMPLE_STRUCTS = NO
|
||||
TYPEDEF_HIDES_STRUCT = NO
|
||||
LOOKUP_CACHE_SIZE = 0
|
||||
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = YES
|
||||
EXTRACT_PACKAGE = YES
|
||||
EXTRACT_STATIC = YES
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = YES
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
HIDE_COMPOUND_REFERENCE= NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
SHOW_GROUPED_MEMB_INC = NO
|
||||
FORCE_LOCAL_INCLUDES = NO
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_MEMBERS_CTORS_1ST = NO
|
||||
SORT_GROUP_NAMES = NO
|
||||
SORT_BY_SCOPE_NAME = YES
|
||||
STRICT_PROTO_MATCHING = NO
|
||||
GENERATE_TODOLIST = NO
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST= YES
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = YES
|
||||
SHOW_FILES = YES
|
||||
SHOW_NAMESPACES = YES
|
||||
FILE_VERSION_FILTER =
|
||||
LAYOUT_FILE =
|
||||
CITE_BIB_FILES =
|
||||
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_AS_ERROR = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE = doxygen.warn
|
||||
|
||||
INPUT = ../amathc.h .
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS =
|
||||
RECURSIVE = NO
|
||||
EXCLUDE = amathc.dox
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS =
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
FILTER_SOURCE_PATTERNS =
|
||||
USE_MDFILE_AS_MAINPAGE = NO
|
||||
|
||||
SOURCE_BROWSER = YES
|
||||
INLINE_SOURCES = YES
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = NO
|
||||
REFERENCES_RELATION = NO
|
||||
REFERENCES_LINK_SOURCE = NO
|
||||
SOURCE_TOOLTIPS = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
CLANG_ASSISTED_PARSING = YES
|
||||
CLANG_OPTIONS =
|
||||
|
||||
ALPHABETICAL_INDEX = YES
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
|
||||
GENERATE_MAN = YES
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_SUBDIR =
|
||||
MAN_LINKS = NO
|
||||
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED = UNIX
|
||||
EXPAND_AS_DEFINED = YES
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
|
||||
GENERATE_HTML = NO
|
||||
GENERATE_LATEX = NO
|
||||
GENERATE_RTF = NO
|
||||
GENERATE_XML = NO
|
||||
GENERATE_DOCBOOK = NO
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
GENERATE_PERLMOD = NO
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = NO
|
||||
EXTERNAL_PAGES = NO
|
||||
CLASS_DIAGRAMS = NO
|
||||
+1
-1
@@ -5,6 +5,6 @@ libdir=${exec_prefix}/lib
|
||||
|
||||
Name: amath C library
|
||||
Description: C functions for manipulating strings and memory
|
||||
Version: 1.7.1
|
||||
Version: 1.8.0
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lamathc
|
||||
|
||||
+621
-726
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,154 @@
|
||||
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = "amathi"
|
||||
PROJECT_NUMBER = "1.8.0"
|
||||
PROJECT_BRIEF = "Complex numbers math library"
|
||||
PROJECT_LOGO =
|
||||
OUTPUT_DIRECTORY =
|
||||
CREATE_SUBDIRS = NO
|
||||
ALLOW_UNICODE_NAMES = NO
|
||||
OUTPUT_LANGUAGE = English
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ABBREVIATE_BRIEF =
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = NO
|
||||
STRIP_FROM_PATH =
|
||||
STRIP_FROM_INC_PATH =
|
||||
SHORT_NAMES = NO
|
||||
JAVADOC_AUTOBRIEF = NO
|
||||
QT_AUTOBRIEF = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
INHERIT_DOCS = YES
|
||||
SEPARATE_MEMBER_PAGES = NO
|
||||
TAB_SIZE = 4
|
||||
ALIASES =
|
||||
TCL_SUBST =
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_JAVA = NO
|
||||
OPTIMIZE_FOR_FORTRAN = NO
|
||||
OPTIMIZE_OUTPUT_VHDL = NO
|
||||
EXTENSION_MAPPING = C
|
||||
MARKDOWN_SUPPORT = YES
|
||||
AUTOLINK_SUPPORT = YES
|
||||
BUILTIN_STL_SUPPORT = NO
|
||||
CPP_CLI_SUPPORT = NO
|
||||
SIP_SUPPORT = NO
|
||||
IDL_PROPERTY_SUPPORT = YES
|
||||
DISTRIBUTE_GROUP_DOC = NO
|
||||
GROUP_NESTED_COMPOUNDS = NO
|
||||
SUBGROUPING = YES
|
||||
INLINE_GROUPED_CLASSES = NO
|
||||
INLINE_SIMPLE_STRUCTS = NO
|
||||
TYPEDEF_HIDES_STRUCT = NO
|
||||
LOOKUP_CACHE_SIZE = 0
|
||||
|
||||
EXTRACT_ALL = YES
|
||||
EXTRACT_PRIVATE = YES
|
||||
EXTRACT_PACKAGE = YES
|
||||
EXTRACT_STATIC = YES
|
||||
EXTRACT_LOCAL_CLASSES = YES
|
||||
EXTRACT_LOCAL_METHODS = NO
|
||||
EXTRACT_ANON_NSPACES = NO
|
||||
HIDE_UNDOC_MEMBERS = NO
|
||||
HIDE_UNDOC_CLASSES = NO
|
||||
HIDE_FRIEND_COMPOUNDS = NO
|
||||
HIDE_IN_BODY_DOCS = NO
|
||||
INTERNAL_DOCS = NO
|
||||
CASE_SENSE_NAMES = YES
|
||||
HIDE_SCOPE_NAMES = NO
|
||||
HIDE_COMPOUND_REFERENCE= NO
|
||||
SHOW_INCLUDE_FILES = YES
|
||||
SHOW_GROUPED_MEMB_INC = NO
|
||||
FORCE_LOCAL_INCLUDES = NO
|
||||
INLINE_INFO = YES
|
||||
SORT_MEMBER_DOCS = YES
|
||||
SORT_BRIEF_DOCS = NO
|
||||
SORT_MEMBERS_CTORS_1ST = NO
|
||||
SORT_GROUP_NAMES = NO
|
||||
SORT_BY_SCOPE_NAME = YES
|
||||
STRICT_PROTO_MATCHING = NO
|
||||
GENERATE_TODOLIST = NO
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST= YES
|
||||
ENABLED_SECTIONS =
|
||||
MAX_INITIALIZER_LINES = 30
|
||||
SHOW_USED_FILES = YES
|
||||
SHOW_FILES = YES
|
||||
SHOW_NAMESPACES = YES
|
||||
FILE_VERSION_FILTER =
|
||||
LAYOUT_FILE =
|
||||
CITE_BIB_FILES =
|
||||
|
||||
QUIET = NO
|
||||
WARNINGS = YES
|
||||
WARN_IF_UNDOCUMENTED = YES
|
||||
WARN_IF_DOC_ERROR = YES
|
||||
WARN_NO_PARAMDOC = NO
|
||||
WARN_AS_ERROR = NO
|
||||
WARN_FORMAT = "$file:$line: $text"
|
||||
WARN_LOGFILE = doxygen.warn
|
||||
|
||||
INPUT = ../mathi.h .
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS =
|
||||
RECURSIVE = NO
|
||||
EXCLUDE = amathi.dox
|
||||
EXCLUDE_SYMLINKS = NO
|
||||
EXCLUDE_PATTERNS =
|
||||
EXCLUDE_SYMBOLS =
|
||||
EXAMPLE_PATH =
|
||||
EXAMPLE_PATTERNS =
|
||||
EXAMPLE_RECURSIVE = NO
|
||||
IMAGE_PATH =
|
||||
INPUT_FILTER =
|
||||
FILTER_PATTERNS =
|
||||
FILTER_SOURCE_FILES = NO
|
||||
FILTER_SOURCE_PATTERNS =
|
||||
USE_MDFILE_AS_MAINPAGE = NO
|
||||
|
||||
SOURCE_BROWSER = YES
|
||||
INLINE_SOURCES = YES
|
||||
STRIP_CODE_COMMENTS = YES
|
||||
REFERENCED_BY_RELATION = NO
|
||||
REFERENCES_RELATION = NO
|
||||
REFERENCES_LINK_SOURCE = NO
|
||||
SOURCE_TOOLTIPS = YES
|
||||
USE_HTAGS = NO
|
||||
VERBATIM_HEADERS = YES
|
||||
CLANG_ASSISTED_PARSING = YES
|
||||
CLANG_OPTIONS =
|
||||
|
||||
ALPHABETICAL_INDEX = YES
|
||||
COLS_IN_ALPHA_INDEX = 5
|
||||
IGNORE_PREFIX =
|
||||
|
||||
GENERATE_MAN = YES
|
||||
MAN_OUTPUT = man
|
||||
MAN_EXTENSION = .3
|
||||
MAN_SUBDIR =
|
||||
MAN_LINKS = NO
|
||||
|
||||
ENABLE_PREPROCESSING = YES
|
||||
MACRO_EXPANSION = NO
|
||||
EXPAND_ONLY_PREDEF = NO
|
||||
SEARCH_INCLUDES = YES
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_FILE_PATTERNS =
|
||||
PREDEFINED = UNIX
|
||||
EXPAND_AS_DEFINED = YES
|
||||
SKIP_FUNCTION_MACROS = YES
|
||||
|
||||
GENERATE_HTML = NO
|
||||
GENERATE_LATEX = NO
|
||||
GENERATE_RTF = NO
|
||||
GENERATE_XML = NO
|
||||
GENERATE_DOCBOOK = NO
|
||||
GENERATE_AUTOGEN_DEF = NO
|
||||
GENERATE_PERLMOD = NO
|
||||
ALLEXTERNALS = NO
|
||||
EXTERNAL_GROUPS = NO
|
||||
EXTERNAL_PAGES = NO
|
||||
CLASS_DIAGRAMS = NO
|
||||
+2
-2
@@ -4,7 +4,7 @@ includedir=${prefix}/include/amath
|
||||
libdir=${exec_prefix}/lib
|
||||
|
||||
Name: amath complex library
|
||||
Description: Functions for handling complex numbers
|
||||
Version: 1.7.1
|
||||
Description: Complex numbers math library
|
||||
Version: 1.8.0
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lamathi
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse cosine of complex number
|
||||
* @version 1.0
|
||||
* @date 14/09/15
|
||||
* @brief Inverse cosine of complex number
|
||||
* @details
|
||||
* Inverse cosine expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic cosine of complex number
|
||||
* @version 1.1
|
||||
* @date 15/03/03
|
||||
* @brief Inverse hyperbolic cosine of complex number
|
||||
* @details
|
||||
* Inverse hyperbolic cosine expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse cotangent of complex number
|
||||
* @version 1.1
|
||||
* @date 14/10/01
|
||||
* @brief Inverse cotangent of complex number
|
||||
* @details
|
||||
* Inverse cotangent expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic cotangent of complex number
|
||||
* @version 1.0
|
||||
* @date 14/09/15
|
||||
* @brief Inverse hyperbolic cotangent of complex number
|
||||
* @details
|
||||
* Inverse hyperbolic cotangent expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse cosecant of complex number
|
||||
* @version 1.1
|
||||
* @date 14/10/01
|
||||
* @brief Inverse cosecant of complex number
|
||||
* @details
|
||||
* Inverse cosecant expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic cosecant of complex number
|
||||
* @version 1.0
|
||||
* @date 14/09/15
|
||||
* @brief Inverse hyperbolic cosecant of complex number
|
||||
* @details
|
||||
* Inverse hyperbolic cosecant expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse secant expressed using complex logarithms:
|
||||
* @version 1.1
|
||||
* @date 14/10/01
|
||||
* @details
|
||||
* Inverse secant expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-6
@@ -28,18 +28,13 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic secant of complex numbers
|
||||
* @version 1.1
|
||||
* @date 15/03/03
|
||||
* @brief Inverse hyperbolic secant of complex numbers
|
||||
* @details
|
||||
* Inverse hyperbolic secant expressed using complex logarithms:
|
||||
* <pre>
|
||||
* asech(z) = log(sqrt(1 / (z * z) - 1) + 1/z)
|
||||
*
|
||||
* </pre>
|
||||
* More info is available at Wikipedia: <BR>
|
||||
* https://wikipedia.org/wiki/Inverse_hyperbolic_function#Logarithmic_representation
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse sine of complex number
|
||||
* @version 1.1
|
||||
* @date 14/10/01
|
||||
* @brief Inverse sine of complex number
|
||||
* @details
|
||||
* Inverse sine expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+2
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic sine of complex number
|
||||
* @version 1.0
|
||||
* @date 14/09/15
|
||||
* @brief Inverse hyperbolic sine of complex number
|
||||
* @details
|
||||
* Inverse hyperbolic sine expressed using complex logarithms:
|
||||
* <pre>
|
||||
@@ -50,6 +46,7 @@
|
||||
*/
|
||||
complex casinh(complex z)
|
||||
{
|
||||
// TODO: Fix branch cuts
|
||||
complex one = cpack(1.0, 0.0);
|
||||
complex a = cadd(cmul(z, z), one);
|
||||
complex b = cadd(z, csqrt(a));
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse tangent of complex number
|
||||
* @version 1.1
|
||||
* @date 14/10/01
|
||||
* @brief Inverse tangent of complex number
|
||||
* @details
|
||||
* Inverse tangent expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-5
@@ -28,13 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic tangent of complex number
|
||||
* @version 1.0
|
||||
* @date 14/09/15
|
||||
* @brief Inverse hyperbolic tangent of complex number
|
||||
* @details
|
||||
* Inverse hyperbolic tangent expressed using complex logarithms:
|
||||
* <pre>
|
||||
|
||||
+1
-3
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Cube root of complex number
|
||||
* @brief Cube root of complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* cbrt z = exp(1/3 * log(z))
|
||||
|
||||
+1
-5
@@ -32,13 +32,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Cosine of complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @brief Cosine of complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* a+bi
|
||||
|
||||
+1
-5
@@ -35,13 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic cosine of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @brief Hyperbolic cosine of a complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* a+bi
|
||||
|
||||
+2
-4
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Cotangent of a complex number
|
||||
* @brief Cotangent of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:
|
||||
* <pre>
|
||||
@@ -59,7 +57,7 @@ complex ccot(complex z)
|
||||
|
||||
if (d == 0.0)
|
||||
{
|
||||
w = cpack(D_INFP, D_INFP);
|
||||
w = cpack((double)INFP, (double)INFP);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-3
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic cotangent of a complex number
|
||||
* @brief Hyperbolic cotangent of a complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* acoth(z) = 0.5 * (log(1 + 1/z) - log(1 - 1/z))
|
||||
|
||||
+2
-4
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Cosecant of a complex number
|
||||
* @brief Cosecant of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:
|
||||
* <pre>
|
||||
@@ -59,7 +57,7 @@ complex ccsc(complex z)
|
||||
|
||||
if (d == 0.0)
|
||||
{
|
||||
w = cpack(D_INFP, D_INFP);
|
||||
w = cpack((double)INFP, (double)INFP);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-3
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic secant of a complex number
|
||||
* @brief Hyperbolic secant of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:
|
||||
* <pre>
|
||||
|
||||
+1
-6
@@ -35,14 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Returns e to the power of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @details
|
||||
* @brief Returns e to the power of a complex number
|
||||
*/
|
||||
complex cexp(complex z)
|
||||
{
|
||||
|
||||
+1
-6
@@ -35,14 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Natural logarithm of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @details
|
||||
* @brief Natural logarithm of a complex number
|
||||
*/
|
||||
complex clog(complex z)
|
||||
{
|
||||
|
||||
+1
-2
@@ -28,10 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Base 10 logarithmic value of complex number.
|
||||
* @brief Base 10 logarithmic value of complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* log z = log(z) / log(10)
|
||||
|
||||
+1
-2
@@ -28,10 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Base 2 logarithmic value of complex number.
|
||||
* @brief Base 2 logarithmic value of complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* lb z = log(z) / log(2)
|
||||
|
||||
+1
-6
@@ -35,14 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Complex number raised to a power
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @details
|
||||
* @brief Complex number raised to a power
|
||||
*/
|
||||
complex cpow(complex a, complex z)
|
||||
{
|
||||
|
||||
+2
-4
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Secant of a complex number
|
||||
* @brief Secant of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:<BR>
|
||||
* https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSEC_function
|
||||
@@ -59,7 +57,7 @@ complex csec(complex z)
|
||||
|
||||
if (d == 0.0)
|
||||
{
|
||||
w = cpack(D_INFP, D_INFP);
|
||||
w = cpack((double)INFP, (double)INFP);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-3
@@ -28,11 +28,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic secant of a complex number
|
||||
* @brief Hyperbolic secant of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:<BR>
|
||||
* https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSECH_function
|
||||
|
||||
+1
-2
@@ -30,11 +30,10 @@
|
||||
#include "prim.h"
|
||||
|
||||
/**
|
||||
* @brief Complex signum
|
||||
* @brief Complex signum
|
||||
* @details
|
||||
* More info is available at Wikipedia: <BR>
|
||||
* https://wikipedia.org/wiki/Sign_function#Complex_signum
|
||||
*
|
||||
*/
|
||||
double csgn(complex z)
|
||||
{
|
||||
|
||||
+1
-5
@@ -35,13 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Sine of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @brief Sine of a complex number
|
||||
* @details
|
||||
* Calculated according to description at wikipedia:<BR>
|
||||
* https://wikipedia.org/wiki/Sine#Sine_with_a_complex_argument
|
||||
|
||||
+1
-5
@@ -35,13 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic sine of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @brief Hyperbolic sine of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:<BR>
|
||||
* https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMSINH_function
|
||||
|
||||
+1
-6
@@ -35,14 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Square root of complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @details
|
||||
* @brief Square root of complex number
|
||||
*/
|
||||
complex csqrt(complex z)
|
||||
{
|
||||
|
||||
+2
-6
@@ -35,13 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Tangent of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @brief Tangent of a complex number
|
||||
* @details
|
||||
* Calculated as in Open Office:<BR>
|
||||
* https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_IMTAN_function
|
||||
@@ -68,7 +64,7 @@ complex ctan(complex z)
|
||||
|
||||
if (d == 0.0)
|
||||
{
|
||||
w = cpack(D_INFP, D_INFP);
|
||||
w = cpack((double)INFP, (double)INFP);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-5
@@ -35,13 +35,9 @@
|
||||
*/
|
||||
|
||||
#include "prim.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic tangent of a complex number
|
||||
* @version 1.1
|
||||
* @date 2007/08/20
|
||||
* @brief Hyperbolic tangent of a complex number
|
||||
* @details
|
||||
* <pre>
|
||||
* a+bi
|
||||
|
||||
+13
-30
@@ -27,16 +27,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "prim.h"
|
||||
#include "complex.h"
|
||||
|
||||
#define REAL_PART(z) ((z).parts[0])
|
||||
#define IMAG_PART(z) ((z).parts[1])
|
||||
|
||||
/**
|
||||
* @brief Real part of complex number.
|
||||
*
|
||||
* @brief Real part of complex number
|
||||
*/
|
||||
double creal(complex z)
|
||||
{
|
||||
@@ -44,8 +41,7 @@ double creal(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Imaginary part of complex number.
|
||||
*
|
||||
* @brief Imaginary part of complex number
|
||||
*/
|
||||
double cimag(complex z)
|
||||
{
|
||||
@@ -53,8 +49,7 @@ double cimag(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Absolute value of complex number.
|
||||
*
|
||||
* @brief Absolute value of complex number
|
||||
*/
|
||||
double cabs(complex z)
|
||||
{
|
||||
@@ -68,8 +63,7 @@ complex conj(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pack two real numbers into a complex number.
|
||||
*
|
||||
* @brief Pack two real numbers into a complex number
|
||||
*/
|
||||
complex cpack(double x, double y)
|
||||
{
|
||||
@@ -81,8 +75,7 @@ complex cpack(double x, double y)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Truncated value of complex number.
|
||||
*
|
||||
* @brief Truncated value of complex number
|
||||
*/
|
||||
complex ctrunc(complex z)
|
||||
{
|
||||
@@ -92,8 +85,7 @@ complex ctrunc(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Floor value of complex number.
|
||||
*
|
||||
* @brief Floor value of complex number
|
||||
*/
|
||||
complex cfloor(complex z)
|
||||
{
|
||||
@@ -103,8 +95,7 @@ complex cfloor(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Ceiling value of complex number.
|
||||
*
|
||||
* @brief Ceiling value of complex number
|
||||
*/
|
||||
complex cceil(complex z)
|
||||
{
|
||||
@@ -114,8 +105,7 @@ complex cceil(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Division of two complex numbers.
|
||||
*
|
||||
* @brief Division of two complex numbers
|
||||
*/
|
||||
complex cround(complex z)
|
||||
{
|
||||
@@ -125,8 +115,7 @@ complex cround(complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Addition of two complex numbers.
|
||||
*
|
||||
* @brief Addition of two complex numbers
|
||||
*/
|
||||
complex cadd(complex y, complex z)
|
||||
{
|
||||
@@ -136,8 +125,7 @@ complex cadd(complex y, complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Subtraction of two complex numbers.
|
||||
*
|
||||
* @brief Subtraction of two complex numbers
|
||||
*/
|
||||
complex csub(complex y, complex z)
|
||||
{
|
||||
@@ -147,8 +135,7 @@ complex csub(complex y, complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Multiplication of two complex numbers.
|
||||
*
|
||||
* @brief Multiplication of two complex numbers
|
||||
*/
|
||||
complex cmul(complex y, complex z)
|
||||
{
|
||||
@@ -167,8 +154,7 @@ complex cmul(complex y, complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Division of two complex numbers.
|
||||
*
|
||||
* @brief Division of two complex numbers
|
||||
*/
|
||||
complex cdiv(complex y, complex z)
|
||||
{
|
||||
@@ -190,8 +176,7 @@ complex cdiv(complex y, complex z)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reciprocal value of complex number.
|
||||
*
|
||||
* @brief Reciprocal value of complex number
|
||||
*/
|
||||
complex creci(complex z)
|
||||
{
|
||||
@@ -208,7 +193,6 @@ complex creci(complex z)
|
||||
|
||||
/**
|
||||
* @brief Calculate cosh and sinh
|
||||
*
|
||||
*/
|
||||
void cchsh(double x, double* c, double* s)
|
||||
{
|
||||
@@ -231,7 +215,6 @@ void cchsh(double x, double* c, double* s)
|
||||
|
||||
/**
|
||||
* @brief Calculate cosh and cos
|
||||
*
|
||||
*/
|
||||
void cchc(double x, double* ch, double* c)
|
||||
{
|
||||
|
||||
+2
-2
@@ -36,8 +36,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
#include "../mathr.h"
|
||||
#include "../mathi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+29
-3
@@ -39,6 +39,7 @@
|
||||
#define INSERT1CHAR "\x1B[1@"
|
||||
#define DELETE1CHAR "\x1B[1P"
|
||||
#define DELETELINE "\x0D\x1B[K"
|
||||
#define DELETE1CHARASC "\b \b"
|
||||
|
||||
AnsiConoleEngine::AnsiConoleEngine(const char* prompt, CharValidator* validator)
|
||||
{
|
||||
@@ -56,6 +57,7 @@ AnsiConoleEngine::AnsiConoleEngine(const char* prompt, CharValidator* validator)
|
||||
|
||||
editline = nullptr;
|
||||
curline = -1;
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
AnsiConoleEngine::~AnsiConoleEngine()
|
||||
@@ -74,6 +76,16 @@ AnsiConoleEngine::~AnsiConoleEngine()
|
||||
delete prompt;
|
||||
}
|
||||
|
||||
void AnsiConoleEngine::Enable()
|
||||
{
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void AnsiConoleEngine::Disable()
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
void AnsiConoleEngine::StartInput()
|
||||
{
|
||||
linebuf->ClearAndAlloc(lineSize + 1);
|
||||
@@ -172,7 +184,14 @@ const char* AnsiConoleEngine::ProcessChar(const unsigned char character)
|
||||
while (i != endpos);
|
||||
|
||||
len++;
|
||||
out->Append(DELETE1CHAR);
|
||||
if (enabled)
|
||||
{
|
||||
out->Append(DELETE1CHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
out->Append(DELETE1CHARASC);
|
||||
}
|
||||
endpos--;
|
||||
linebuf->ptr = endpos;
|
||||
}
|
||||
@@ -208,8 +227,15 @@ const char* AnsiConoleEngine::ProcessChar(const unsigned char character)
|
||||
}
|
||||
|
||||
len++;
|
||||
out->Append(CURSORBACKWARD);
|
||||
out->Append(DELETE1CHAR);
|
||||
if (enabled)
|
||||
{
|
||||
out->Append(CURSORBACKWARD);
|
||||
out->Append(DELETE1CHAR);
|
||||
}
|
||||
else
|
||||
{
|
||||
out->Append(DELETE1CHARASC);
|
||||
}
|
||||
cursor--;
|
||||
endpos--;
|
||||
linebuf->ptr = endpos;
|
||||
|
||||
+6
-4
@@ -32,17 +32,16 @@
|
||||
|
||||
/**
|
||||
* @file aengine.h
|
||||
* @brief ANSI Console Engine.
|
||||
*
|
||||
* @brief ANSI Console Engine
|
||||
*/
|
||||
|
||||
class CharBuffer;
|
||||
class CharValidator;
|
||||
|
||||
/**
|
||||
* @brief ANSI console controller.
|
||||
* @brief ANSI console controller
|
||||
* @details
|
||||
* More info on the ANSI console is available at [Wikipedia]:
|
||||
* More info on the ANSI console is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/ANSI_escape_code
|
||||
*/
|
||||
class AnsiConoleEngine
|
||||
@@ -56,6 +55,8 @@ public:
|
||||
const char* GetLine() const;
|
||||
void SetPrompt(const char* string);
|
||||
const char* ProcessChar(const unsigned char character);
|
||||
void Enable();
|
||||
void Disable();
|
||||
|
||||
private:
|
||||
void CopyLine();
|
||||
@@ -63,6 +64,7 @@ private:
|
||||
void ShowNext();
|
||||
|
||||
char* prompt;
|
||||
bool enabled;
|
||||
|
||||
static const int maxLines = 100;
|
||||
static const int lineSize = 1024;
|
||||
|
||||
+1
-1
@@ -5,6 +5,6 @@ libdir=${exec_prefix}/lib
|
||||
|
||||
Name: amath application library
|
||||
Description: C++ library for handling numbers
|
||||
Version: 1.7.1
|
||||
Version: 1.8.0
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -lamathapp -lamathr -lamathi -lamathc
|
||||
|
||||
@@ -0,0 +1,999 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014 Ryan Juckett
|
||||
* http://www.ryanjuckett.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not
|
||||
* be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
|
||||
#include "bigint.h"
|
||||
#include "mathr.h"
|
||||
|
||||
static int32_t BigInt_Compare(const BigInt &lhs, const BigInt &rhs)
|
||||
{
|
||||
// A bigger length implies a bigger number.
|
||||
int32_t lengthDiff = lhs.m_length - rhs.m_length;
|
||||
if (lengthDiff != 0)
|
||||
return lengthDiff;
|
||||
|
||||
// Compare blocks one by one from high to low.
|
||||
for (int32_t i = lhs.m_length - 1; i >= 0; --i)
|
||||
{
|
||||
if (lhs.m_blocks[i] == rhs.m_blocks[i])
|
||||
continue;
|
||||
else if (lhs.m_blocks[i] > rhs.m_blocks[i])
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
// no blocks differed
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void BigInt_Add(BigInt *pResult, const BigInt &lhs, const BigInt &rhs)
|
||||
{
|
||||
// determine which operand has the smaller length
|
||||
const BigInt *pLarge;
|
||||
const BigInt *pSmall;
|
||||
if (lhs.m_length < rhs.m_length)
|
||||
{
|
||||
pSmall = &lhs;
|
||||
pLarge = &rhs;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSmall = &rhs;
|
||||
pLarge = &lhs;
|
||||
}
|
||||
|
||||
const uint32_t largeLen = pLarge->m_length;
|
||||
const uint32_t smallLen = pSmall->m_length;
|
||||
|
||||
// The output will be at least as long as the largest input
|
||||
pResult->m_length = largeLen;
|
||||
|
||||
// Add each block and add carry the overflow to the next block
|
||||
uint64_t carry = 0;
|
||||
const uint32_t *pLargeCur = pLarge->m_blocks;
|
||||
const uint32_t *pLargeEnd = pLargeCur + largeLen;
|
||||
const uint32_t *pSmallCur = pSmall->m_blocks;
|
||||
const uint32_t *pSmallEnd = pSmallCur + smallLen;
|
||||
uint32_t *pResultCur = pResult->m_blocks;
|
||||
while (pSmallCur != pSmallEnd)
|
||||
{
|
||||
uint64_t sum = carry + (uint64_t)(*pLargeCur) + (uint64_t)(*pSmallCur);
|
||||
carry = sum >> 32;
|
||||
(*pResultCur) = sum & 0xFFFFFFFF;
|
||||
++pLargeCur;
|
||||
++pSmallCur;
|
||||
++pResultCur;
|
||||
}
|
||||
|
||||
// Add the carry to any blocks that only exist in the large operand
|
||||
while (pLargeCur != pLargeEnd)
|
||||
{
|
||||
uint64_t sum = carry + (uint64_t)(*pLargeCur);
|
||||
carry = sum >> 32;
|
||||
(*pResultCur) = sum & 0xFFFFFFFF;
|
||||
++pLargeCur;
|
||||
++pResultCur;
|
||||
}
|
||||
|
||||
// If there's still a carry, append a new block
|
||||
if (carry != 0)
|
||||
{
|
||||
assert(carry == 1);
|
||||
assert((uint32_t)(pResultCur - pResult->m_blocks) == largeLen && (largeLen < c_BigInt_MaxBlocks));
|
||||
*pResultCur = 1;
|
||||
pResult->m_length = largeLen + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pResult->m_length = largeLen;
|
||||
}
|
||||
}
|
||||
|
||||
static void BigInt_Multiply(BigInt *pResult, const BigInt &lhs, const BigInt &rhs)
|
||||
{
|
||||
assert(pResult != &lhs && pResult != &rhs);
|
||||
|
||||
// determine which operand has the smaller length
|
||||
const BigInt *pLarge;
|
||||
const BigInt *pSmall;
|
||||
if (lhs.m_length < rhs.m_length)
|
||||
{
|
||||
pSmall = &lhs;
|
||||
pLarge = &rhs;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSmall = &rhs;
|
||||
pLarge = &lhs;
|
||||
}
|
||||
|
||||
// set the maximum possible result length
|
||||
uint32_t maxResultLen = pLarge->m_length + pSmall->m_length;
|
||||
assert(maxResultLen <= c_BigInt_MaxBlocks);
|
||||
|
||||
// clear the result data
|
||||
for (uint32_t *pCur = pResult->m_blocks, *pEnd = pCur + maxResultLen; pCur != pEnd; ++pCur)
|
||||
*pCur = 0;
|
||||
|
||||
// perform standard long multiplication
|
||||
const uint32_t *pLargeBeg = pLarge->m_blocks;
|
||||
const uint32_t *pLargeEnd = pLargeBeg + pLarge->m_length;
|
||||
|
||||
// for each small block
|
||||
uint32_t *pResultStart = pResult->m_blocks;
|
||||
for (const uint32_t *pSmallCur = pSmall->m_blocks, *pSmallEnd = pSmallCur + pSmall->m_length;
|
||||
pSmallCur != pSmallEnd;
|
||||
++pSmallCur, ++pResultStart)
|
||||
{
|
||||
// if non-zero, multiply against all the large blocks and add into the result
|
||||
const uint32_t multiplier = *pSmallCur;
|
||||
if (multiplier != 0)
|
||||
{
|
||||
const uint32_t *pLargeCur = pLargeBeg;
|
||||
uint32_t *pResultCur = pResultStart;
|
||||
uint64_t carry = 0;
|
||||
do
|
||||
{
|
||||
uint64_t product = (*pResultCur) + (*pLargeCur) * (uint64_t)multiplier + carry;
|
||||
carry = product >> 32;
|
||||
*pResultCur = product & 0xFFFFFFFF;
|
||||
++pLargeCur;
|
||||
++pResultCur;
|
||||
} while (pLargeCur != pLargeEnd);
|
||||
|
||||
assert(pResultCur < pResult->m_blocks + maxResultLen);
|
||||
*pResultCur = (uint32_t)(carry & 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
// check if the terminating block has no set bits
|
||||
if (maxResultLen > 0 && pResult->m_blocks[maxResultLen - 1] == 0)
|
||||
pResult->m_length = maxResultLen - 1;
|
||||
else
|
||||
pResult->m_length = maxResultLen;
|
||||
}
|
||||
|
||||
static void BigInt_Multiply(BigInt *pResult, const BigInt &lhs, uint32_t rhs)
|
||||
{
|
||||
// perform long multiplication
|
||||
uint32_t carry = 0;
|
||||
uint32_t *pResultCur = pResult->m_blocks;
|
||||
const uint32_t *pLhsCur = lhs.m_blocks;
|
||||
const uint32_t *pLhsEnd = lhs.m_blocks + lhs.m_length;
|
||||
for (; pLhsCur != pLhsEnd; ++pLhsCur, ++pResultCur)
|
||||
{
|
||||
uint64_t product = (uint64_t)(*pLhsCur) * rhs + carry;
|
||||
*pResultCur = (uint32_t)(product & 0xFFFFFFFF);
|
||||
carry = product >> 32;
|
||||
}
|
||||
|
||||
// if there is a remaining carry, grow the array
|
||||
if (carry != 0)
|
||||
{
|
||||
// grow the array
|
||||
assert(lhs.m_length + 1 <= c_BigInt_MaxBlocks);
|
||||
*pResultCur = (uint32_t)carry;
|
||||
pResult->m_length = lhs.m_length + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pResult->m_length = lhs.m_length;
|
||||
}
|
||||
}
|
||||
|
||||
static void BigInt_Multiply2(BigInt *pResult, const BigInt &in)
|
||||
{
|
||||
// shift all the blocks by one
|
||||
uint32_t carry = 0;
|
||||
|
||||
uint32_t *pResultCur = pResult->m_blocks;
|
||||
const uint32_t *pLhsCur = in.m_blocks;
|
||||
const uint32_t *pLhsEnd = in.m_blocks + in.m_length;
|
||||
for (; pLhsCur != pLhsEnd; ++pLhsCur, ++pResultCur)
|
||||
{
|
||||
uint32_t cur = *pLhsCur;
|
||||
*pResultCur = (cur << 1) | carry;
|
||||
carry = cur >> 31;
|
||||
}
|
||||
|
||||
if (carry != 0)
|
||||
{
|
||||
// grow the array
|
||||
assert(in.m_length + 1 <= c_BigInt_MaxBlocks);
|
||||
*pResultCur = carry;
|
||||
pResult->m_length = in.m_length + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pResult->m_length = in.m_length;
|
||||
}
|
||||
}
|
||||
|
||||
static void BigInt_Multiply2(BigInt *pResult)
|
||||
{
|
||||
// shift all the blocks by one
|
||||
uint32_t carry = 0;
|
||||
|
||||
uint32_t *pCur = pResult->m_blocks;
|
||||
uint32_t *pEnd = pResult->m_blocks + pResult->m_length;
|
||||
for (; pCur != pEnd; ++pCur)
|
||||
{
|
||||
uint32_t cur = *pCur;
|
||||
*pCur = (cur << 1) | carry;
|
||||
carry = cur >> 31;
|
||||
}
|
||||
|
||||
if (carry != 0)
|
||||
{
|
||||
// grow the array
|
||||
assert(pResult->m_length + 1 <= c_BigInt_MaxBlocks);
|
||||
*pCur = carry;
|
||||
++pResult->m_length;
|
||||
}
|
||||
}
|
||||
|
||||
static void BigInt_Multiply10(BigInt *pResult)
|
||||
{
|
||||
// multiply all the blocks
|
||||
uint64_t carry = 0;
|
||||
|
||||
uint32_t *pCur = pResult->m_blocks;
|
||||
uint32_t *pEnd = pResult->m_blocks + pResult->m_length;
|
||||
for (; pCur != pEnd; ++pCur)
|
||||
{
|
||||
uint64_t product = (uint64_t)(*pCur) * 10ull + carry;
|
||||
(*pCur) = (uint32_t)(product & 0xFFFFFFFF);
|
||||
carry = product >> 32;
|
||||
}
|
||||
|
||||
if (carry != 0)
|
||||
{
|
||||
// grow the array
|
||||
assert(pResult->m_length + 1 <= c_BigInt_MaxBlocks);
|
||||
*pCur = (uint32_t)carry;
|
||||
++pResult->m_length;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t g_PowerOf10_U32[] =
|
||||
{
|
||||
1, // 10 ^ 0
|
||||
10, // 10 ^ 1
|
||||
100, // 10 ^ 2
|
||||
1000, // 10 ^ 3
|
||||
10000, // 10 ^ 4
|
||||
100000, // 10 ^ 5
|
||||
1000000, // 10 ^ 6
|
||||
10000000, // 10 ^ 7
|
||||
};
|
||||
|
||||
static BigInt g_PowerOf10_Big[] =
|
||||
{
|
||||
// 10 ^ 8
|
||||
{1,
|
||||
{100000000}},
|
||||
// 10 ^ 16
|
||||
{2,
|
||||
{0x6fc10000, 0x002386f2}},
|
||||
// 10 ^ 32
|
||||
{4, {
|
||||
0x00000000, 0x85acef81, 0x2d6d415b, 0x000004ee,
|
||||
}},
|
||||
// 10 ^ 64
|
||||
{7, {
|
||||
0x00000000, 0x00000000, 0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x00184f03,
|
||||
}},
|
||||
// 10 ^ 128
|
||||
{14, {
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x2e953e01, 0x03df9909, 0x0f1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08, 0xbccdb0da, 0xa6337f19, 0xe91f2603, 0x0000024e,
|
||||
}},
|
||||
// 10 ^ 256
|
||||
{27, {
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6, 0xcf4a6e70, 0xd595d80f, 0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e, 0xcc5573c0, 0x65f9ef17, 0x55bc28f2, 0x80dcc7f7, 0xf46eeddc, 0x5fdcefce, 0x000553f7,
|
||||
}}};
|
||||
|
||||
static void BigInt_Pow10(BigInt *pResult, uint32_t exponent)
|
||||
{
|
||||
// make sure the exponent is within the bounds of the lookup table data
|
||||
assert(exponent < 512);
|
||||
|
||||
// create two temporary values to reduce large integer copy operations
|
||||
BigInt temp1;
|
||||
BigInt temp2;
|
||||
BigInt *pCurTemp = &temp1;
|
||||
BigInt *pNextTemp = &temp2;
|
||||
|
||||
// initialize the result by looking up a 32-bit power of 10 corresponding to the first 3 bits
|
||||
uint32_t smallExponent = exponent & 0x7;
|
||||
pCurTemp->SetUInt32(g_PowerOf10_U32[smallExponent]);
|
||||
|
||||
// remove the low bits that we used for the 32-bit lookup table
|
||||
exponent >>= 3;
|
||||
uint32_t tableIdx = 0;
|
||||
|
||||
// while there are remaining bits in the exponent to be processed
|
||||
while (exponent != 0)
|
||||
{
|
||||
// if the current bit is set, multiply it with the corresponding power of 10
|
||||
if (exponent & 1)
|
||||
{
|
||||
// multiply into the next temporary
|
||||
BigInt_Multiply(pNextTemp, *pCurTemp, g_PowerOf10_Big[tableIdx]);
|
||||
|
||||
// swap to the next temporary
|
||||
BigInt *pSwap = pCurTemp;
|
||||
pCurTemp = pNextTemp;
|
||||
pNextTemp = pSwap;
|
||||
}
|
||||
|
||||
// advance to the next bit
|
||||
++tableIdx;
|
||||
exponent >>= 1;
|
||||
}
|
||||
|
||||
// output the result
|
||||
*pResult = *pCurTemp;
|
||||
}
|
||||
|
||||
static void BigInt_MultiplyPow10(BigInt *pResult, const BigInt &in, uint32_t exponent)
|
||||
{
|
||||
// make sure the exponent is within the bounds of the lookup table data
|
||||
assert(exponent < 512);
|
||||
|
||||
// create two temporary values to reduce large integer copy operations
|
||||
BigInt temp1;
|
||||
BigInt temp2;
|
||||
BigInt *pCurTemp = &temp1;
|
||||
BigInt *pNextTemp = &temp2;
|
||||
|
||||
// initialize the result by looking up a 32-bit power of 10 corresponding to the first 3 bits
|
||||
uint32_t smallExponent = exponent & 0x7;
|
||||
if (smallExponent != 0)
|
||||
{
|
||||
BigInt_Multiply(pCurTemp, in, g_PowerOf10_U32[smallExponent]);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pCurTemp = in;
|
||||
}
|
||||
|
||||
// remove the low bits that we used for the 32-bit lookup table
|
||||
exponent >>= 3;
|
||||
uint32_t tableIdx = 0;
|
||||
|
||||
// while there are remaining bits in the exponent to be processed
|
||||
while (exponent != 0)
|
||||
{
|
||||
// if the current bit is set, multiply it with the corresponding power of 10
|
||||
if (exponent & 1)
|
||||
{
|
||||
// multiply into the next temporary
|
||||
BigInt_Multiply(pNextTemp, *pCurTemp, g_PowerOf10_Big[tableIdx]);
|
||||
|
||||
// swap to the next temporary
|
||||
BigInt *pSwap = pCurTemp;
|
||||
pCurTemp = pNextTemp;
|
||||
pNextTemp = pSwap;
|
||||
}
|
||||
|
||||
// advance to the next bit
|
||||
++tableIdx;
|
||||
exponent >>= 1;
|
||||
}
|
||||
|
||||
// output the result
|
||||
*pResult = *pCurTemp;
|
||||
}
|
||||
|
||||
static inline void BigInt_Pow2(BigInt *pResult, uint32_t exponent)
|
||||
{
|
||||
uint32_t blockIdx = exponent / 32;
|
||||
assert(blockIdx < c_BigInt_MaxBlocks);
|
||||
|
||||
for (uint32_t i = 0; i <= blockIdx; ++i)
|
||||
pResult->m_blocks[i] = 0;
|
||||
|
||||
pResult->m_length = blockIdx + 1;
|
||||
|
||||
uint32_t bitIdx = (exponent % 32);
|
||||
pResult->m_blocks[blockIdx] |= (1 << bitIdx);
|
||||
}
|
||||
|
||||
static uint32_t BigInt_DivideWithRemainder_MaxQuotient9(BigInt *pDividend, const BigInt &divisor)
|
||||
{
|
||||
// Check that the divisor has been correctly shifted into range and that it is not
|
||||
// smaller than the dividend in length.
|
||||
assert(!divisor.IsZero() &&
|
||||
divisor.m_blocks[divisor.m_length - 1] >= 8 &&
|
||||
divisor.m_blocks[divisor.m_length - 1] < 0xFFFFFFFF &&
|
||||
pDividend->m_length <= divisor.m_length);
|
||||
|
||||
// If the dividend is smaller than the divisor, the quotient is zero and the divisor is already
|
||||
// the remainder.
|
||||
uint32_t length = divisor.m_length;
|
||||
if (pDividend->m_length < divisor.m_length)
|
||||
return 0;
|
||||
|
||||
const uint32_t *pFinalDivisorBlock = divisor.m_blocks + length - 1;
|
||||
uint32_t *pFinalDividendBlock = pDividend->m_blocks + length - 1;
|
||||
|
||||
// Compute an estimated quotient based on the high block value. This will either match the actual quotient or
|
||||
// undershoot by one.
|
||||
uint32_t quotient = *pFinalDividendBlock / (*pFinalDivisorBlock + 1);
|
||||
assert(quotient <= 9);
|
||||
|
||||
// Divide out the estimated quotient
|
||||
if (quotient != 0)
|
||||
{
|
||||
// dividend = dividend - divisor*quotient
|
||||
const uint32_t *pDivisorCur = divisor.m_blocks;
|
||||
uint32_t *pDividendCur = pDividend->m_blocks;
|
||||
|
||||
uint64_t borrow = 0;
|
||||
uint64_t carry = 0;
|
||||
do
|
||||
{
|
||||
uint64_t product = (uint64_t)*pDivisorCur * (uint64_t)quotient + carry;
|
||||
carry = product >> 32;
|
||||
|
||||
uint64_t difference = (uint64_t)*pDividendCur - (product & 0xFFFFFFFF) - borrow;
|
||||
borrow = (difference >> 32) & 1;
|
||||
|
||||
*pDividendCur = difference & 0xFFFFFFFF;
|
||||
|
||||
++pDivisorCur;
|
||||
++pDividendCur;
|
||||
} while (pDivisorCur <= pFinalDivisorBlock);
|
||||
|
||||
// remove all leading zero blocks from dividend
|
||||
while (length > 0 && pDividend->m_blocks[length - 1] == 0)
|
||||
--length;
|
||||
|
||||
pDividend->m_length = length;
|
||||
}
|
||||
|
||||
// If the dividend is still larger than the divisor, we overshot our estimate quotient. To correct,
|
||||
// we increment the quotient and subtract one more divisor from the dividend.
|
||||
if (BigInt_Compare(*pDividend, divisor) >= 0)
|
||||
{
|
||||
++quotient;
|
||||
|
||||
// dividend = dividend - divisor
|
||||
const uint32_t *pDivisorCur = divisor.m_blocks;
|
||||
uint32_t *pDividendCur = pDividend->m_blocks;
|
||||
|
||||
uint64_t borrow = 0;
|
||||
do
|
||||
{
|
||||
uint64_t difference = (uint64_t)*pDividendCur - (uint64_t)*pDivisorCur - borrow;
|
||||
borrow = (difference >> 32) & 1;
|
||||
|
||||
*pDividendCur = difference & 0xFFFFFFFF;
|
||||
|
||||
++pDivisorCur;
|
||||
++pDividendCur;
|
||||
} while (pDivisorCur <= pFinalDivisorBlock);
|
||||
|
||||
// remove all leading zero blocks from dividend
|
||||
while (length > 0 && pDividend->m_blocks[length - 1] == 0)
|
||||
--length;
|
||||
|
||||
pDividend->m_length = length;
|
||||
}
|
||||
|
||||
return quotient;
|
||||
}
|
||||
|
||||
static void BigInt_ShiftLeft(BigInt *pResult, uint32_t shift)
|
||||
{
|
||||
assert(shift != 0);
|
||||
|
||||
uint32_t shifboollocks = shift / 32;
|
||||
uint32_t shifboolits = shift % 32;
|
||||
|
||||
// process blocks high to low so that we can safely process in place
|
||||
const uint32_t *pInBlocks = pResult->m_blocks;
|
||||
int32_t inLength = pResult->m_length;
|
||||
assert(inLength + shifboollocks < c_BigInt_MaxBlocks);
|
||||
|
||||
// check if the shift is block aligned
|
||||
if (shifboolits == 0)
|
||||
{
|
||||
// copy blcoks from high to low
|
||||
for (uint32_t *pInCur = pResult->m_blocks + inLength, *pOutCur = pInCur + shifboollocks;
|
||||
pInCur >= pInBlocks;
|
||||
--pInCur, --pOutCur)
|
||||
{
|
||||
*pOutCur = *pInCur;
|
||||
}
|
||||
|
||||
// zero the remaining low blocks
|
||||
for (uint32_t i = 0; i < shifboollocks; ++i)
|
||||
pResult->m_blocks[i] = 0;
|
||||
|
||||
pResult->m_length += shifboollocks;
|
||||
}
|
||||
// else we need to shift partial blocks
|
||||
else
|
||||
{
|
||||
int32_t inBlockIdx = inLength - 1;
|
||||
uint32_t ouboollockIdx = inLength + shifboollocks;
|
||||
|
||||
// set the length to hold the shifted blocks
|
||||
assert(ouboollockIdx < c_BigInt_MaxBlocks);
|
||||
pResult->m_length = ouboollockIdx + 1;
|
||||
|
||||
// output the initial blocks
|
||||
const uint32_t lowBitsShift = (32 - shifboolits);
|
||||
uint32_t highBits = 0;
|
||||
uint32_t block = pResult->m_blocks[inBlockIdx];
|
||||
uint32_t lowBits = block >> lowBitsShift;
|
||||
while (inBlockIdx > 0)
|
||||
{
|
||||
pResult->m_blocks[ouboollockIdx] = highBits | lowBits;
|
||||
highBits = block << shifboolits;
|
||||
|
||||
--inBlockIdx;
|
||||
--ouboollockIdx;
|
||||
|
||||
block = pResult->m_blocks[inBlockIdx];
|
||||
lowBits = block >> lowBitsShift;
|
||||
}
|
||||
|
||||
// output the final blocks
|
||||
assert(ouboollockIdx == shifboollocks + 1);
|
||||
pResult->m_blocks[ouboollockIdx] = highBits | lowBits;
|
||||
pResult->m_blocks[ouboollockIdx - 1] = block << shifboolits;
|
||||
|
||||
// zero the remaining low blocks
|
||||
for (uint32_t i = 0; i < shifboollocks; ++i)
|
||||
pResult->m_blocks[i] = 0;
|
||||
|
||||
// check if the terminating block has no set bits
|
||||
if (pResult->m_blocks[pResult->m_length - 1] == 0)
|
||||
--pResult->m_length;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Dragon4(
|
||||
const uint64_t mantissa, // value significand
|
||||
const int32_t exponent, // value exponent in base 2
|
||||
const uint32_t mantissaHighBitIdx, // index of the highest set mantissa bit
|
||||
const bool hasUnequalMargins, // is the high margin twice as large as the low margin
|
||||
const tCutoffMode cutoffMode, // how to determine output length
|
||||
uint32_t cutoffNumber, // parameter to the selected cutoffMode
|
||||
char *pOubooluffer, // buffer to output into
|
||||
uint32_t bufferSize, // maximum characters that can be printed to pOubooluffer
|
||||
int32_t *pOutExponent // the base 10 exponent of the first digit
|
||||
)
|
||||
{
|
||||
char *pCurDigit = pOubooluffer;
|
||||
|
||||
assert(bufferSize > 0);
|
||||
|
||||
// if the mantissa is zero, the value is zero regardless of the exponent
|
||||
if (mantissa == 0)
|
||||
{
|
||||
*pCurDigit = '0';
|
||||
*pOutExponent = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// compute the initial state in integral form such that
|
||||
// value = scaledValue / scale
|
||||
// marginLow = scaledMarginLow / scale
|
||||
BigInt scale; // positive scale applied to value and margin such that they can be
|
||||
// represented as whole numbers
|
||||
BigInt scaledValue; // scale * mantissa
|
||||
BigInt scaledMarginLow; // scale * 0.5 * (distance between this floating-point number and its
|
||||
// immediate lower value)
|
||||
|
||||
// For normalized IEEE floating point values, each time the exponent is incremented the margin also
|
||||
// doubles. That creates a subset of transition numbers where the high margin is twice the size of
|
||||
// the low margin.
|
||||
BigInt *pScaledMarginHigh;
|
||||
BigInt optionalMarginHigh;
|
||||
|
||||
if (hasUnequalMargins)
|
||||
{
|
||||
// if we have no fractional component
|
||||
if (exponent > 0)
|
||||
{
|
||||
// 1) Expand the input value by multiplying out the mantissa and exponent. This represents
|
||||
// the input value in its whole number representation.
|
||||
// 2) Apply an additional scale of 2 such that later comparisons against the margin values
|
||||
// are simplified.
|
||||
// 3) Set the margin value to the lowest mantissa bit's scale.
|
||||
|
||||
// scaledValue = 2 * 2 * mantissa*2^exponent
|
||||
scaledValue.SetUInt64(4 * mantissa);
|
||||
BigInt_ShiftLeft(&scaledValue, exponent);
|
||||
|
||||
// scale = 2 * 2 * 1
|
||||
scale.SetUInt32(4);
|
||||
|
||||
// scaledMarginLow = 2 * 2^(exponent-1)
|
||||
BigInt_Pow2(&scaledMarginLow, exponent);
|
||||
|
||||
// scaledMarginHigh = 2 * 2 * 2^(exponent-1)
|
||||
BigInt_Pow2(&optionalMarginHigh, exponent + 1);
|
||||
}
|
||||
// else we have a fractional exponent
|
||||
else
|
||||
{
|
||||
// In order to track the mantissa data as an integer, we store it as is with a large scale
|
||||
|
||||
// scaledValue = 2 * 2 * mantissa
|
||||
scaledValue.SetUInt64(4 * mantissa);
|
||||
|
||||
// scale = 2 * 2 * 2^(-exponent)
|
||||
BigInt_Pow2(&scale, -exponent + 2);
|
||||
|
||||
// scaledMarginLow = 2 * 2^(-1)
|
||||
scaledMarginLow.SetUInt32(1);
|
||||
|
||||
// scaledMarginHigh = 2 * 2 * 2^(-1)
|
||||
optionalMarginHigh.SetUInt32(2);
|
||||
}
|
||||
|
||||
// the high and low margins are different
|
||||
pScaledMarginHigh = &optionalMarginHigh;
|
||||
}
|
||||
else
|
||||
{
|
||||
// if we have no fractional component
|
||||
if (exponent > 0)
|
||||
{
|
||||
// 1) Expand the input value by multiplying out the mantissa and exponent. This represents
|
||||
// the input value in its whole number representation.
|
||||
// 2) Apply an additional scale of 2 such that later comparisons against the margin values
|
||||
// are simplified.
|
||||
// 3) Set the margin value to the lowest mantissa bit's scale.
|
||||
|
||||
// scaledValue = 2 * mantissa*2^exponent
|
||||
scaledValue.SetUInt64(2 * mantissa);
|
||||
BigInt_ShiftLeft(&scaledValue, exponent);
|
||||
|
||||
// scale = 2 * 1
|
||||
scale.SetUInt32(2);
|
||||
|
||||
// scaledMarginLow = 2 * 2^(exponent-1)
|
||||
BigInt_Pow2(&scaledMarginLow, exponent);
|
||||
}
|
||||
// else we have a fractional exponent
|
||||
else
|
||||
{
|
||||
// In order to track the mantissa data as an integer, we store it as is with a large scale
|
||||
|
||||
// scaledValue = 2 * mantissa
|
||||
scaledValue.SetUInt64(2 * mantissa);
|
||||
|
||||
// scale = 2 * 2^(-exponent)
|
||||
BigInt_Pow2(&scale, -exponent + 1);
|
||||
|
||||
// scaledMarginLow = 2 * 2^(-1)
|
||||
scaledMarginLow.SetUInt32(1);
|
||||
}
|
||||
|
||||
// the high and low margins are equal
|
||||
pScaledMarginHigh = &scaledMarginLow;
|
||||
}
|
||||
|
||||
// Compute an estimate for digitExponent that will be correct or undershoot by one.
|
||||
// This optimization is based on the paper "Printing Floating-Point Numbers Quickly and Accurately"
|
||||
// by Burger and Dybvig http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.4656&rep=rep1&type=pdf
|
||||
// We perform an additional subtraction of 0.69 to increase the frequency of a failed estimate
|
||||
// because that lets us take a faster branch in the code. 0.69 is chosen because 0.69 + log10(2) is
|
||||
// less than one by a reasonable epsilon that will account for any floating point error.
|
||||
//
|
||||
// We want to set digitExponent to floor(log10(v)) + 1
|
||||
// v = mantissa*2^exponent
|
||||
// log2(v) = log2(mantissa) + exponent;
|
||||
// log10(v) = log2(v) * log10(2)
|
||||
// floor(log2(v)) = mantissaHighBitIdx + exponent;
|
||||
// log10(v) - log10(2) < (mantissaHighBitIdx + exponent) * log10(2) <= log10(v)
|
||||
// log10(v) < (mantissaHighBitIdx + exponent) * log10(2) + log10(2) <= log10(v) + log10(2)
|
||||
// floor( log10(v) ) < ceil( (mantissaHighBitIdx + exponent) * log10(2) ) <= floor( log10(v) ) + 1
|
||||
const double log10_2 = 0.30102999566398119521373889472449;
|
||||
int32_t digitExponent = (int32_t)(ceil(double((int32_t)mantissaHighBitIdx + exponent) * log10_2 - 0.69));
|
||||
|
||||
// if the digit exponent is smaller than the smallest desired digit for fractional cutoff,
|
||||
// pull the digit back into legal range at which point we will round to the appropriate value.
|
||||
// Note that while our value for digitExponent is still an estimate, this is safe because it
|
||||
// only increases the number. This will either correct digitExponent to an accurate value or it
|
||||
// will clamp it above the accurate value.
|
||||
if (cutoffMode == CutoffMode_FractionLength && digitExponent <= -(int32_t)cutoffNumber)
|
||||
{
|
||||
digitExponent = -(int32_t)cutoffNumber + 1;
|
||||
}
|
||||
|
||||
// Divide value by 10^digitExponent.
|
||||
if (digitExponent > 0)
|
||||
{
|
||||
// The exponent is positive creating a division so we multiply up the scale.
|
||||
BigInt temp;
|
||||
BigInt_MultiplyPow10(&temp, scale, digitExponent);
|
||||
scale = temp;
|
||||
}
|
||||
else if (digitExponent < 0)
|
||||
{
|
||||
// The exponent is negative creating a multiplication so we multiply up the scaledValue,
|
||||
// scaledMarginLow and scaledMarginHigh.
|
||||
BigInt pow10;
|
||||
BigInt_Pow10(&pow10, -digitExponent);
|
||||
|
||||
BigInt temp;
|
||||
BigInt_Multiply(&temp, scaledValue, pow10);
|
||||
scaledValue = temp;
|
||||
|
||||
BigInt_Multiply(&temp, scaledMarginLow, pow10);
|
||||
scaledMarginLow = temp;
|
||||
|
||||
if (pScaledMarginHigh != &scaledMarginLow)
|
||||
BigInt_Multiply2(pScaledMarginHigh, scaledMarginLow);
|
||||
}
|
||||
|
||||
// If (value >= 1), our estimate for digitExponent was too low
|
||||
if (BigInt_Compare(scaledValue, scale) >= 0)
|
||||
{
|
||||
// The exponent estimate was incorrect.
|
||||
// Increment the exponent and don't perform the premultiply needed
|
||||
// for the first loop iteration.
|
||||
digitExponent = digitExponent + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The exponent estimate was correct.
|
||||
// Multiply larger by the output base to prepare for the first loop iteration.
|
||||
BigInt_Multiply10(&scaledValue);
|
||||
BigInt_Multiply10(&scaledMarginLow);
|
||||
if (pScaledMarginHigh != &scaledMarginLow)
|
||||
BigInt_Multiply2(pScaledMarginHigh, scaledMarginLow);
|
||||
}
|
||||
|
||||
// Compute the cutoff exponent (the exponent of the final digit to print).
|
||||
// Default to the maximum size of the output buffer.
|
||||
int32_t cutoffExponent = digitExponent - bufferSize;
|
||||
switch (cutoffMode)
|
||||
{
|
||||
// print digits until we pass the accuracy margin limits or buffer size
|
||||
case CutoffMode_Unique:
|
||||
break;
|
||||
|
||||
// print cutoffNumber of digits or until we reach the buffer size
|
||||
case CutoffMode_TotalLength:
|
||||
{
|
||||
int32_t desiredCutoffExponent = digitExponent - (int32_t)cutoffNumber;
|
||||
if (desiredCutoffExponent > cutoffExponent)
|
||||
cutoffExponent = desiredCutoffExponent;
|
||||
}
|
||||
break;
|
||||
|
||||
// print cutoffNumber digits past the decimal point or until we reach the buffer size
|
||||
case CutoffMode_FractionLength:
|
||||
{
|
||||
int32_t desiredCutoffExponent = -(int32_t)cutoffNumber;
|
||||
if (desiredCutoffExponent > cutoffExponent)
|
||||
cutoffExponent = desiredCutoffExponent;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Output the exponent of the first digit we will print
|
||||
*pOutExponent = digitExponent - 1;
|
||||
|
||||
// In preparation for calling BigInt_DivideWithRemainder_MaxQuotient9(),
|
||||
// we need to scale up our values such that the highest block of the denominator
|
||||
// is greater than or equal to 8. We also need to guarantee that the numerator
|
||||
// can never have a length greater than the denominator after each loop iteration.
|
||||
// This requires the highest block of the denominator to be less than or equal to
|
||||
// 429496729 which is the highest number that can be multiplied by 10 without
|
||||
// overflowing to a new block.
|
||||
assert(scale.GetLength() > 0);
|
||||
uint32_t hiBlock = scale.Geboollock(scale.GetLength() - 1);
|
||||
if (hiBlock < 8 || hiBlock > 429496729)
|
||||
{
|
||||
// Perform a bit shift on all values to get the highest block of the denominator into
|
||||
// the range [8,429496729]. We are more likely to make accurate quotient estimations
|
||||
// in BigInt_DivideWithRemainder_MaxQuotient9() with higher denominator values so
|
||||
// we shift the denominator to place the highest bit at index 27 of the highest block.
|
||||
// This is safe because (2^28 - 1) = 268435455 which is less than 429496729. This means
|
||||
// that all values with a highest bit at index 27 are within range.
|
||||
uint32_t hiBlockLog2 = log2i(hiBlock);
|
||||
assert(hiBlockLog2 < 3 || hiBlockLog2 > 27);
|
||||
uint32_t shift = (32 + 27 - hiBlockLog2) % 32;
|
||||
|
||||
BigInt_ShiftLeft(&scale, shift);
|
||||
BigInt_ShiftLeft(&scaledValue, shift);
|
||||
BigInt_ShiftLeft(&scaledMarginLow, shift);
|
||||
if (pScaledMarginHigh != &scaledMarginLow)
|
||||
BigInt_Multiply2(pScaledMarginHigh, scaledMarginLow);
|
||||
}
|
||||
|
||||
// These values are used to inspect why the print loop terminated so we can properly
|
||||
// round the final digit.
|
||||
bool low; // did the value get within marginLow distance from zero
|
||||
bool high; // did the value get within marginHigh distance from one
|
||||
uint32_t outputDigit; // current digit being output
|
||||
|
||||
if (cutoffMode == CutoffMode_Unique)
|
||||
{
|
||||
// For the unique cutoff mode, we will try to print until we have reached a level of
|
||||
// precision that uniquely distinguishes this value from its neighbors. If we run
|
||||
// out of space in the output buffer, we terminate early.
|
||||
for (;;)
|
||||
{
|
||||
digitExponent = digitExponent - 1;
|
||||
|
||||
// divide out the scale to extract the digit
|
||||
outputDigit = BigInt_DivideWithRemainder_MaxQuotient9(&scaledValue, scale);
|
||||
assert(outputDigit < 10);
|
||||
|
||||
// update the high end of the value
|
||||
BigInt scaledValueHigh;
|
||||
BigInt_Add(&scaledValueHigh, scaledValue, *pScaledMarginHigh);
|
||||
|
||||
// stop looping if we are far enough away from our neighboring values
|
||||
// or if we have reached the cutoff digit
|
||||
low = BigInt_Compare(scaledValue, scaledMarginLow) < 0;
|
||||
high = BigInt_Compare(scaledValueHigh, scale) > 0;
|
||||
if (low | high | (digitExponent == cutoffExponent))
|
||||
break;
|
||||
|
||||
// store the output digit
|
||||
*pCurDigit = (char)('0' + outputDigit);
|
||||
++pCurDigit;
|
||||
|
||||
// multiply larger by the output base
|
||||
BigInt_Multiply10(&scaledValue);
|
||||
BigInt_Multiply10(&scaledMarginLow);
|
||||
if (pScaledMarginHigh != &scaledMarginLow)
|
||||
BigInt_Multiply2(pScaledMarginHigh, scaledMarginLow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// For length based cutoff modes, we will try to print until we
|
||||
// have exhausted all precision (i.e. all remaining digits are zeros) or
|
||||
// until we reach the desired cutoff digit.
|
||||
low = false;
|
||||
high = false;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
digitExponent = digitExponent - 1;
|
||||
|
||||
// divide out the scale to extract the digit
|
||||
outputDigit = BigInt_DivideWithRemainder_MaxQuotient9(&scaledValue, scale);
|
||||
assert(outputDigit < 10);
|
||||
|
||||
if (scaledValue.IsZero() | (digitExponent == cutoffExponent))
|
||||
break;
|
||||
|
||||
// store the output digit
|
||||
*pCurDigit = (char)('0' + outputDigit);
|
||||
++pCurDigit;
|
||||
|
||||
// multiply larger by the output base
|
||||
BigInt_Multiply10(&scaledValue);
|
||||
}
|
||||
}
|
||||
|
||||
// round off the final digit
|
||||
// default to rounding down if value got too close to 0
|
||||
bool roundDown = low;
|
||||
|
||||
// if it is legal to round up and down
|
||||
if (low == high)
|
||||
{
|
||||
// round to the closest digit by comparing value with 0.5. To do this we need to convert
|
||||
// the inequality to large integer values.
|
||||
// compare( value, 0.5 )
|
||||
// compare( scale * value, scale * 0.5 )
|
||||
// compare( 2 * scale * value, scale )
|
||||
BigInt_Multiply2(&scaledValue);
|
||||
int32_t compare = BigInt_Compare(scaledValue, scale);
|
||||
roundDown = compare < 0;
|
||||
|
||||
// if we are directly in the middle, round towards the even digit (i.e. IEEE rouding rules)
|
||||
if (compare == 0)
|
||||
roundDown = (outputDigit & 1) == 0;
|
||||
}
|
||||
|
||||
// print the rounded digit
|
||||
if (roundDown)
|
||||
{
|
||||
*pCurDigit = (char)('0' + outputDigit);
|
||||
++pCurDigit;
|
||||
}
|
||||
else
|
||||
{
|
||||
// handle rounding up
|
||||
if (outputDigit == 9)
|
||||
{
|
||||
// find the first non-nine prior digit
|
||||
for (;;)
|
||||
{
|
||||
// if we are at the first digit
|
||||
if (pCurDigit == pOubooluffer)
|
||||
{
|
||||
// output 1 at the next highest exponent
|
||||
*pCurDigit = '1';
|
||||
++pCurDigit;
|
||||
*pOutExponent += 1;
|
||||
break;
|
||||
}
|
||||
|
||||
--pCurDigit;
|
||||
if (*pCurDigit != '9')
|
||||
{
|
||||
// increment the digit
|
||||
*pCurDigit += 1;
|
||||
++pCurDigit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// values in the range [0,8] can perform a simple round up
|
||||
*pCurDigit = (char)('0' + outputDigit + 1);
|
||||
++pCurDigit;
|
||||
}
|
||||
}
|
||||
|
||||
// return the number of digits output
|
||||
uint32_t outputLen = (uint32_t)(pCurDigit - pOubooluffer);
|
||||
assert(outputLen <= bufferSize);
|
||||
return outputLen;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014 Ryan Juckett
|
||||
* http://www.ryanjuckett.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
|
||||
#ifndef AMATH_BIGINT_H
|
||||
#define AMATH_BIGINT_H
|
||||
|
||||
#include "amath.h"
|
||||
|
||||
const uint32_t c_BigInt_MaxBlocks = 35;
|
||||
|
||||
struct BigInt
|
||||
{
|
||||
BigInt &operator=(const BigInt &rhs)
|
||||
{
|
||||
uint32_t length = rhs.m_length;
|
||||
uint32_t *pLhsCur = m_blocks;
|
||||
for (const uint32_t *pRhsCur = rhs.m_blocks, *pRhsEnd = pRhsCur + length;
|
||||
pRhsCur != pRhsEnd;
|
||||
++pLhsCur, ++pRhsCur)
|
||||
{
|
||||
*pLhsCur = *pRhsCur;
|
||||
}
|
||||
m_length = length;
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint32_t GetLength() const { return m_length; }
|
||||
uint32_t Geboollock(uint32_t idx) const { return m_blocks[idx]; }
|
||||
void SetZero() { m_length = 0; }
|
||||
bool IsZero() const { return m_length == 0; }
|
||||
|
||||
void SetUInt64(uint64_t val)
|
||||
{
|
||||
if (val > 0xFFFFFFFF)
|
||||
{
|
||||
m_blocks[0] = val & 0xFFFFFFFF;
|
||||
m_blocks[1] = (val >> 32) & 0xFFFFFFFF;
|
||||
m_length = 2;
|
||||
}
|
||||
else if (val != 0)
|
||||
{
|
||||
m_blocks[0] = val & 0xFFFFFFFF;
|
||||
m_length = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetUInt32(uint32_t val)
|
||||
{
|
||||
if (val != 0)
|
||||
{
|
||||
m_blocks[0] = val;
|
||||
m_length = (val != 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t GetUInt32() const { return (m_length == 0) ? 0 : m_blocks[0]; }
|
||||
|
||||
uint32_t m_length;
|
||||
uint32_t m_blocks[c_BigInt_MaxBlocks];
|
||||
};
|
||||
|
||||
enum tCutoffMode
|
||||
{
|
||||
CutoffMode_Unique, // as many digits as necessary to print a uniquely identifiable number
|
||||
CutoffMode_TotalLength, // up to cutoffNumber significant digits
|
||||
CutoffMode_FractionLength, // up to cutoffNumber significant digits past the decimal point
|
||||
};
|
||||
|
||||
uint32_t Dragon4(
|
||||
uint64_t mantissa, // value significand
|
||||
int32_t exponent, // value exponent in base 2
|
||||
uint32_t mantissaHighBitIdx, // index of the highest set mantissa bit
|
||||
bool hasUnequalMargins, // is the high margin twice as large as the low margin
|
||||
tCutoffMode cutoffMode, // how to determine output length
|
||||
uint32_t cutoffNumber, // parameter to the selected cutoffMode
|
||||
char *pOubooluffer, // buffer to output into
|
||||
uint32_t bufferSize, // maximum characters that can be printed to pOubooluffer
|
||||
int32_t *pOutExponent // the base 10 exponent of the first digit
|
||||
);
|
||||
|
||||
#endif
|
||||
@@ -171,6 +171,26 @@ void CharBuffer::EnsureGrowth(unsigned int size)
|
||||
EnsureSize((unsigned int)((ptr - buf) + size));
|
||||
}
|
||||
|
||||
bool CharBuffer::IsEmpty() const
|
||||
{
|
||||
char* i = buf;
|
||||
|
||||
if (i == nullptr || buf == ptr)
|
||||
return true;
|
||||
|
||||
do
|
||||
{
|
||||
// Blank space characters
|
||||
if (*i != ' ' && *i != '\t' && *i != '\r' && *i != '\n')
|
||||
return false;
|
||||
|
||||
i++;
|
||||
}
|
||||
while (i != ptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CharBuffer::Is(const char* string) const
|
||||
{
|
||||
return StrIsEqual(GetString(), string);
|
||||
|
||||
+4
-4
@@ -32,16 +32,14 @@
|
||||
|
||||
/**
|
||||
* @file charbuf.h
|
||||
* @brief String and character array logic.
|
||||
*
|
||||
* @brief String and character array logic
|
||||
*/
|
||||
|
||||
#include "aengine.h"
|
||||
|
||||
/**
|
||||
* @brief Encapsulate an character array which can be used as a string.
|
||||
* @brief Encapsulate an character array which can be used as a string
|
||||
* @details The CharBuffer class eases the task of allocating a releasing memory.
|
||||
*
|
||||
*/
|
||||
class CharBuffer
|
||||
{
|
||||
@@ -59,6 +57,8 @@ public:
|
||||
|
||||
void Empty();
|
||||
|
||||
bool IsEmpty() const;
|
||||
|
||||
/**
|
||||
* @brief Compare content of CharBuffer with string)
|
||||
*/
|
||||
|
||||
+150
-144
@@ -27,27 +27,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
#include "mathr.h"
|
||||
#include "mathi.h"
|
||||
#include "real.h"
|
||||
#include "cplex.h"
|
||||
#include "nnumb.h"
|
||||
#include "integer.h"
|
||||
|
||||
ComplexNumber::ComplexNumber() :
|
||||
Number(nsyscomplex)
|
||||
ComplexNumber::ComplexNumber() : Number(nsyscomplex)
|
||||
{
|
||||
z = cpack(0.0, 0.0);
|
||||
}
|
||||
|
||||
ComplexNumber::ComplexNumber(complex z) :
|
||||
Number(nsyscomplex)
|
||||
ComplexNumber::ComplexNumber(complex z) : Number(nsyscomplex)
|
||||
{
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
ComplexNumber::ComplexNumber(double real, double imag) :
|
||||
Number(nsyscomplex)
|
||||
ComplexNumber::ComplexNumber(double real, double imag) : Number(nsyscomplex)
|
||||
{
|
||||
z = cpack(real, imag);
|
||||
}
|
||||
@@ -56,7 +52,7 @@ ComplexNumber::~ComplexNumber()
|
||||
{
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Clone()
|
||||
Number *ComplexNumber::Clone()
|
||||
{
|
||||
return new ComplexNumber(z);
|
||||
}
|
||||
@@ -107,27 +103,57 @@ int ComplexNumber::GetDefaultPrecedence()
|
||||
return (creal(z) != 0.0 && cimag(z) != 0.0) ? 2 : 0;
|
||||
}
|
||||
|
||||
bool ComplexNumber::IsNegative()
|
||||
{
|
||||
FloatUnion64 d, e;
|
||||
d.floatingPoint = creal(z);
|
||||
e.floatingPoint = cimag(z);
|
||||
return d.IsNegative() && e.IsNegative();
|
||||
}
|
||||
|
||||
bool ComplexNumber::IsZero()
|
||||
{
|
||||
return (creal(z) == 0.0 && cimag(z) == 0.0);
|
||||
}
|
||||
|
||||
bool ComplexNumber::IsTooSmall()
|
||||
{
|
||||
return (creal(z) > 0 && creal(z) < D_INFN) ||
|
||||
(creal(z) < 0 && creal(z) > -D_INFN) ||
|
||||
(cimag(z) > 0 && cimag(z) < D_INFN) ||
|
||||
(cimag(z) < 0 && cimag(z) > -D_INFN);
|
||||
}
|
||||
|
||||
bool ComplexNumber::IsTooLarge()
|
||||
{
|
||||
return (creal(z) > D_INFP) || (cimag(z) > D_INFP);
|
||||
FloatUnion64 d, e;
|
||||
d.floatingPoint = creal(z);
|
||||
e.floatingPoint = cimag(z);
|
||||
return d.IsZero() && e.IsZero();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true if number is NaN
|
||||
*/
|
||||
bool ComplexNumber::IsNaN()
|
||||
{
|
||||
return false;
|
||||
FloatUnion64 d, e;
|
||||
d.floatingPoint = creal(z);
|
||||
e.floatingPoint = cimag(z);
|
||||
return d.IsNaN() || e.IsNaN();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true if number is infinite
|
||||
*/
|
||||
bool ComplexNumber::IsInfinite()
|
||||
{
|
||||
double a = creal(z);
|
||||
double b = cimag(z);
|
||||
|
||||
// Handle subnormal values
|
||||
bool subInf =
|
||||
(a > 0 && a <= 1e-308) || (a < 0 && a >= -1e-308) ||
|
||||
(b > 0 && b <= 1e-308) || (b < 0 && b >= -1e-308);
|
||||
|
||||
if (subInf)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FloatUnion64 d, e;
|
||||
d.floatingPoint = a;
|
||||
e.floatingPoint = b;
|
||||
return d.IsInf() || e.IsInf() ||
|
||||
d.IsMaxPositive() || d.IsMaxNegative() ||
|
||||
e.IsMaxPositive() || e.IsMaxNegative();
|
||||
}
|
||||
|
||||
bool ComplexNumber::IsNotImplemented()
|
||||
@@ -135,193 +161,163 @@ bool ComplexNumber::IsNotImplemented()
|
||||
return false;
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Unary()
|
||||
Number *ComplexNumber::Unary()
|
||||
{
|
||||
complex w = cpack(-creal(z), -cimag(z));
|
||||
return new ComplexNumber(w);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Add(Number* other)
|
||||
Number *ComplexNumber::Add(Number *other)
|
||||
{
|
||||
if (other->IsNaN())
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (other->system == nsyscomplex)
|
||||
{
|
||||
ComplexNumber* w = static_cast<ComplexNumber*>(other);
|
||||
ComplexNumber *w = static_cast<ComplexNumber *>(other);
|
||||
return new ComplexNumber(cadd(z, w->z));
|
||||
}
|
||||
|
||||
if (other->system == nsysreal)
|
||||
{
|
||||
RealNumber* a = static_cast<RealNumber*>(other);
|
||||
RealNumber *a = static_cast<RealNumber *>(other);
|
||||
return new ComplexNumber(cadd(z, cpack(a->x, 0.0)));
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
return new ComplexNumber(cadd(z, cpack(static_cast<double>(a->i), 0.0)));
|
||||
}
|
||||
|
||||
return new ComplexNumber();
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Sub(Number* other)
|
||||
Number *ComplexNumber::Sub(Number *other)
|
||||
{
|
||||
if (other->IsNaN())
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (other->system == nsyscomplex)
|
||||
{
|
||||
ComplexNumber* w = static_cast<ComplexNumber*>(other);
|
||||
ComplexNumber *w = static_cast<ComplexNumber *>(other);
|
||||
return new ComplexNumber(csub(z, w->z));
|
||||
}
|
||||
|
||||
if (other->system == nsysreal)
|
||||
{
|
||||
RealNumber* a = static_cast<RealNumber*>(other);
|
||||
RealNumber *a = static_cast<RealNumber *>(other);
|
||||
return new ComplexNumber(csub(z, cpack(a->x, 0.0)));
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
return new ComplexNumber(csub(z, cpack(static_cast<double>(a->i), 0.0)));
|
||||
}
|
||||
|
||||
return new ComplexNumber();
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Mul(Number* other)
|
||||
Number *ComplexNumber::Mul(Number *other)
|
||||
{
|
||||
if (other->IsNaN())
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (other->system == nsyscomplex)
|
||||
{
|
||||
ComplexNumber* w = static_cast<ComplexNumber*>(other);
|
||||
ComplexNumber *w = static_cast<ComplexNumber *>(other);
|
||||
return new ComplexNumber(cmul(z, w->z));
|
||||
}
|
||||
|
||||
if (other->system == nsysreal)
|
||||
{
|
||||
RealNumber* a = static_cast<RealNumber*>(other);
|
||||
RealNumber *a = static_cast<RealNumber *>(other);
|
||||
return new ComplexNumber(cmul(z, cpack(a->x, 0.0)));
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
return new ComplexNumber(cmul(z, cpack(static_cast<double>(a->i), 0.0)));
|
||||
}
|
||||
|
||||
return new ComplexNumber();
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Div(Number* other)
|
||||
Number *ComplexNumber::Div(Number *other)
|
||||
{
|
||||
if (other->IsZero() || other->IsNaN())
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (other->system == nsyscomplex)
|
||||
{
|
||||
ComplexNumber* w = static_cast<ComplexNumber*>(other);
|
||||
ComplexNumber *w = static_cast<ComplexNumber *>(other);
|
||||
return new ComplexNumber(cdiv(z, w->z));
|
||||
}
|
||||
|
||||
if (other->system == nsysreal)
|
||||
{
|
||||
RealNumber* a = static_cast<RealNumber*>(other);
|
||||
RealNumber *a = static_cast<RealNumber *>(other);
|
||||
return new ComplexNumber(cdiv(z, cpack(a->x, 0.0)));
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
return new ComplexNumber(cdiv(z, cpack(static_cast<double>(a->i), 0.0)));
|
||||
}
|
||||
|
||||
return new ComplexNumber();
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Raise(Number* exponent)
|
||||
Number *ComplexNumber::Raise(Number *exponent)
|
||||
{
|
||||
if (exponent->IsNaN())
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (exponent->system == nsyscomplex)
|
||||
{
|
||||
ComplexNumber* w = static_cast<ComplexNumber*>(exponent);
|
||||
ComplexNumber *w = static_cast<ComplexNumber *>(exponent);
|
||||
return new ComplexNumber(cpow(z, w->z));
|
||||
}
|
||||
|
||||
if (exponent->system == nsysreal)
|
||||
{
|
||||
RealNumber* a = static_cast<RealNumber*>(exponent);
|
||||
RealNumber *a = static_cast<RealNumber *>(exponent);
|
||||
return new ComplexNumber(cpow(z, cpack(a->x, 0.0)));
|
||||
}
|
||||
|
||||
if (exponent->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(exponent);
|
||||
return new ComplexNumber(cpow(z, cpack(static_cast<double>(a->i), 0.0)));
|
||||
}
|
||||
|
||||
return new ComplexNumber();
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Factorial()
|
||||
Number *ComplexNumber::Factorial()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Signum()
|
||||
Number *ComplexNumber::Signum()
|
||||
{
|
||||
return new RealNumber(csgn(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Absolute()
|
||||
Number *ComplexNumber::Absolute()
|
||||
{
|
||||
return new RealNumber(cabs(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Trunc()
|
||||
Number *ComplexNumber::Trunc()
|
||||
{
|
||||
return new ComplexNumber(ctrunc(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Round()
|
||||
Number *ComplexNumber::Round()
|
||||
{
|
||||
return new ComplexNumber(cround(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Floor()
|
||||
Number *ComplexNumber::Floor()
|
||||
{
|
||||
return new ComplexNumber(cfloor(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Ceiling()
|
||||
Number *ComplexNumber::Ceiling()
|
||||
{
|
||||
return new ComplexNumber(cceil(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::SquareRoot()
|
||||
Number *ComplexNumber::SquareRoot()
|
||||
{
|
||||
return new ComplexNumber(csqrt(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Reciprocal()
|
||||
Number *ComplexNumber::Reciprocal()
|
||||
{
|
||||
return new ComplexNumber(creci(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::CubeRoot()
|
||||
Number *ComplexNumber::CubeRoot()
|
||||
{
|
||||
return new ComplexNumber(ccbrt(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Log()
|
||||
Number *ComplexNumber::Log()
|
||||
{
|
||||
if (creal(z) == 0.0 && cimag(z) == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
@@ -329,7 +325,7 @@ Number* ComplexNumber::Log()
|
||||
return new ComplexNumber(clog(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Log2()
|
||||
Number *ComplexNumber::Log2()
|
||||
{
|
||||
if (creal(z) == 0.0 && cimag(z) == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
@@ -337,7 +333,7 @@ Number* ComplexNumber::Log2()
|
||||
return new ComplexNumber(clogb(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Log10()
|
||||
Number *ComplexNumber::Log10()
|
||||
{
|
||||
if (creal(z) == 0.0 && cimag(z) == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
@@ -345,222 +341,232 @@ Number* ComplexNumber::Log10()
|
||||
return new ComplexNumber(clog10(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Sine()
|
||||
Number *ComplexNumber::Sine()
|
||||
{
|
||||
return new ComplexNumber(csin(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Cosine()
|
||||
Number *ComplexNumber::Cosine()
|
||||
{
|
||||
return new ComplexNumber(ccos(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Tangent()
|
||||
Number *ComplexNumber::Tangent()
|
||||
{
|
||||
return new ComplexNumber(ctan(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Secant()
|
||||
Number *ComplexNumber::Secant()
|
||||
{
|
||||
return new ComplexNumber(csec(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Cosecant()
|
||||
Number *ComplexNumber::Cosecant()
|
||||
{
|
||||
return new ComplexNumber(ccsc(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::Cotangent()
|
||||
Number *ComplexNumber::Cotangent()
|
||||
{
|
||||
return new ComplexNumber(ccot(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcSine()
|
||||
Number *ComplexNumber::Chord()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number *ComplexNumber::ExSecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number *ComplexNumber::ExCosecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number *ComplexNumber::ArcSine()
|
||||
{
|
||||
return new ComplexNumber(casin(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcCosine()
|
||||
Number *ComplexNumber::ArcCosine()
|
||||
{
|
||||
return new ComplexNumber(cacos(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcTangent()
|
||||
Number *ComplexNumber::ArcTangent()
|
||||
{
|
||||
return new ComplexNumber(catan(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcSecant()
|
||||
Number *ComplexNumber::ArcSecant()
|
||||
{
|
||||
return new ComplexNumber(casec(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcCosecant()
|
||||
Number *ComplexNumber::ArcCosecant()
|
||||
{
|
||||
return new ComplexNumber(cacsc(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcCotangent()
|
||||
Number *ComplexNumber::ArcCotangent()
|
||||
{
|
||||
return new ComplexNumber(cacot(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypSine()
|
||||
Number *ComplexNumber::ArcChord()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number *ComplexNumber::ArcExSecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number *ComplexNumber::ArcExCosecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number *ComplexNumber::HypSine()
|
||||
{
|
||||
return new ComplexNumber(csinh(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypCosine()
|
||||
Number *ComplexNumber::HypCosine()
|
||||
{
|
||||
return new ComplexNumber(ccosh(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypTangent()
|
||||
Number *ComplexNumber::HypTangent()
|
||||
{
|
||||
return new ComplexNumber(ctanh(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypSecant()
|
||||
Number *ComplexNumber::HypSecant()
|
||||
{
|
||||
return new ComplexNumber(csech(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypCosecant()
|
||||
Number *ComplexNumber::HypCosecant()
|
||||
{
|
||||
return new ComplexNumber(ccsch(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypCotangent()
|
||||
Number *ComplexNumber::HypCotangent()
|
||||
{
|
||||
return new ComplexNumber(ccoth(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypArcSine()
|
||||
Number *ComplexNumber::HypArcSine()
|
||||
{
|
||||
return new ComplexNumber(casinh(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypArcCosine()
|
||||
Number *ComplexNumber::HypArcCosine()
|
||||
{
|
||||
return new ComplexNumber(cacosh(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypArcTangent()
|
||||
Number *ComplexNumber::HypArcTangent()
|
||||
{
|
||||
return new ComplexNumber(catanh(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypArcSecant()
|
||||
Number *ComplexNumber::HypArcSecant()
|
||||
{
|
||||
return new ComplexNumber(casech(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypArcCosecant()
|
||||
Number *ComplexNumber::HypArcCosecant()
|
||||
{
|
||||
return new ComplexNumber(cacsch(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HypArcCotangent()
|
||||
Number *ComplexNumber::HypArcCotangent()
|
||||
{
|
||||
return new ComplexNumber(cacoth(z));
|
||||
}
|
||||
|
||||
Number* ComplexNumber::VerSine()
|
||||
Number *ComplexNumber::VerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::VerCosine()
|
||||
Number *ComplexNumber::VerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::CoVerSine()
|
||||
Number *ComplexNumber::CoVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::CoVerCosine()
|
||||
Number *ComplexNumber::CoVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HaVerSine()
|
||||
Number *ComplexNumber::HaVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HaVerCosine()
|
||||
Number *ComplexNumber::HaVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HaCoVerSine()
|
||||
Number *ComplexNumber::HaCoVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::HaCoVerCosine()
|
||||
Number *ComplexNumber::HaCoVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcVerSine()
|
||||
Number *ComplexNumber::ArcVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcVerCosine()
|
||||
Number *ComplexNumber::ArcVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcCoVerSine()
|
||||
Number *ComplexNumber::ArcCoVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcCoVerCosine()
|
||||
Number *ComplexNumber::ArcCoVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcHaVerSine()
|
||||
Number *ComplexNumber::ArcHaVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcHaVerCosine()
|
||||
Number *ComplexNumber::ArcHaVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcHaCoVerSine()
|
||||
Number *ComplexNumber::ArcHaCoVerSine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcHaCoVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ExSecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ExCosecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcExSecant()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
Number* ComplexNumber::ArcExCosecant()
|
||||
Number *ComplexNumber::ArcHaCoVerCosine()
|
||||
{
|
||||
return new NonNumber(nnnimp);
|
||||
}
|
||||
|
||||
+11
-13
@@ -32,19 +32,16 @@
|
||||
|
||||
/**
|
||||
* @file cplex.h
|
||||
* @brief Class based handling of complex numbers.
|
||||
*
|
||||
* @brief Class based handling of complex numbers
|
||||
*/
|
||||
|
||||
#include "complex.h"
|
||||
#include "numb.h"
|
||||
#include "mathi.h"
|
||||
|
||||
/**
|
||||
* @brief Represent a complex number with 2 components of 15
|
||||
* significant digits.
|
||||
* @brief Represent a complex number with 2 components of 15 significant digits
|
||||
* @details
|
||||
* Calculations are done using 64 bit IEEE 754 arithmetics.
|
||||
*
|
||||
*/
|
||||
struct ComplexNumber : public Number
|
||||
{
|
||||
@@ -62,10 +59,10 @@ public:
|
||||
bool PureComplexValue();
|
||||
int GetPrecedence();
|
||||
int GetDefaultPrecedence();
|
||||
bool IsNegative();
|
||||
bool IsZero();
|
||||
bool IsNaN();
|
||||
bool IsTooSmall();
|
||||
bool IsTooLarge();
|
||||
bool IsInfinite();
|
||||
bool IsNotImplemented();
|
||||
|
||||
Number* Unary();
|
||||
@@ -96,12 +93,18 @@ public:
|
||||
Number* Cosecant();
|
||||
Number* Secant();
|
||||
Number* Cotangent();
|
||||
Number* Chord();
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcSine();
|
||||
Number* ArcCosine();
|
||||
Number* ArcTangent();
|
||||
Number* ArcCosecant();
|
||||
Number* ArcSecant();
|
||||
Number* ArcCotangent();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
Number* ArcChord();
|
||||
|
||||
Number* HypSine();
|
||||
Number* HypCosine();
|
||||
@@ -134,11 +137,6 @@ public:
|
||||
Number* ArcHaCoVerSine();
|
||||
Number* ArcHaCoVerCosine();
|
||||
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
|
||||
private:
|
||||
complex z;
|
||||
};
|
||||
|
||||
@@ -1,808 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "numb.h"
|
||||
#include "real.h"
|
||||
#include "cplex.h"
|
||||
#include "nnumb.h"
|
||||
#include "integer.h"
|
||||
|
||||
IntegerNumber::IntegerNumber() :
|
||||
Number(nsysinteger)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
|
||||
IntegerNumber::IntegerNumber(signed int i) :
|
||||
Number(nsysinteger)
|
||||
{
|
||||
this->i = i;
|
||||
}
|
||||
|
||||
IntegerNumber::IntegerNumber(unsigned int i) :
|
||||
Number(nsysinteger)
|
||||
{
|
||||
this->i = i;
|
||||
}
|
||||
|
||||
IntegerNumber::~IntegerNumber()
|
||||
{
|
||||
}
|
||||
|
||||
Number* IntegerNumber::Clone()
|
||||
{
|
||||
return new IntegerNumber(i);
|
||||
}
|
||||
|
||||
int IntegerNumber::GetIntegerValue()
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
double IntegerNumber::GetRealValue()
|
||||
{
|
||||
return static_cast<double>(i);
|
||||
}
|
||||
|
||||
bool IntegerNumber::PureComplexValue()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int IntegerNumber::GetPrecedence()
|
||||
{
|
||||
return (i < 0) ? -1 : 0;
|
||||
}
|
||||
|
||||
int IntegerNumber::GetDefaultPrecedence()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IntegerNumber::IsZero()
|
||||
{
|
||||
return i == 0;
|
||||
}
|
||||
|
||||
bool IntegerNumber::IsTooSmall()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IntegerNumber::IsTooLarge()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IntegerNumber::IsNaN()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IntegerNumber::IsNotImplemented()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::Unary()
|
||||
{
|
||||
return new IntegerNumber(-i);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::Add(Number* other)
|
||||
{
|
||||
if (other->IsNaN())
|
||||
{
|
||||
return new NonNumber(nnnan);
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
if (a->i > MAX_INT_NUM / 2 || i > MAX_INT_NUM / 2)
|
||||
return new RealNumber(static_cast<double>(a->i) + static_cast<double>(i));
|
||||
|
||||
return new IntegerNumber(i + a->i);
|
||||
}
|
||||
|
||||
return other->Add(this);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::Sub(Number* other)
|
||||
{
|
||||
if (other->IsNaN())
|
||||
{
|
||||
return new NonNumber(nnnan);
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
if (a->i < -MAX_INT_NUM / 2 || i < -MAX_INT_NUM / 2)
|
||||
return new RealNumber(static_cast<double>(a->i) - static_cast<double>(i));
|
||||
|
||||
return new IntegerNumber(i - a->i);
|
||||
}
|
||||
|
||||
Number* y = other->Unary();
|
||||
Number* q = y->Add(this);
|
||||
delete y;
|
||||
return q;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::Mul(Number* other)
|
||||
{
|
||||
if (other->IsNaN())
|
||||
{
|
||||
return new NonNumber(nnnan);
|
||||
}
|
||||
|
||||
if (other->system == nsysinteger)
|
||||
{
|
||||
IntegerNumber* a = static_cast<IntegerNumber*>(other);
|
||||
double r = static_cast<double>(i) * static_cast<double>(a->i);
|
||||
if (r < static_cast<double>(MAX_INT_NUM))
|
||||
return new IntegerNumber(i * a->i);
|
||||
|
||||
return new RealNumber(r);
|
||||
}
|
||||
|
||||
return other->Mul(this);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::Div(Number* other)
|
||||
{
|
||||
if (other->IsZero() || other->IsNaN())
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
Number* y = other->Reciprocal();
|
||||
Number* q = Mul(y);
|
||||
delete y;
|
||||
return q;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Exponentiation function.
|
||||
*
|
||||
* See implementation in pow(double, double)
|
||||
*/
|
||||
Number* IntegerNumber::Raise(Number* exponent)
|
||||
{
|
||||
if (exponent->IsNaN())
|
||||
{
|
||||
return new NonNumber(nnnan);
|
||||
}
|
||||
|
||||
if (exponent->system == nsysinteger)
|
||||
{
|
||||
return new RealNumber(pow(static_cast<double>(i), static_cast<IntegerNumber*>(exponent)->i));
|
||||
}
|
||||
|
||||
if (exponent->system == nsysreal)
|
||||
{
|
||||
return new RealNumber(pow(static_cast<double>(i), static_cast<RealNumber*>(exponent)->GetRealValue()));
|
||||
}
|
||||
|
||||
ComplexNumber* y = new ComplexNumber(i, 0.0);
|
||||
Number* q = y->Raise(exponent);
|
||||
delete y;
|
||||
return q;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mathematical sign function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Signum()
|
||||
{
|
||||
return new IntegerNumber(isgn(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mathematical truncate function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Trunc()
|
||||
{
|
||||
return new IntegerNumber(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mathematical round function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Round()
|
||||
{
|
||||
return new IntegerNumber(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mathematical floor function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Floor()
|
||||
{
|
||||
return new IntegerNumber(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mathematical ceiling function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Ceiling()
|
||||
{
|
||||
return new IntegerNumber(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Absolute value of number.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Absolute()
|
||||
{
|
||||
return new IntegerNumber(abs(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Square root function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::SquareRoot()
|
||||
{
|
||||
if (i == 0)
|
||||
return new IntegerNumber(0);
|
||||
|
||||
if (i > 0)
|
||||
return new RealNumber(sqrt(static_cast<double>(i)));
|
||||
|
||||
Number* n = new ComplexNumber(static_cast<double>(i), 0);
|
||||
Number* r = n->SquareRoot();
|
||||
delete n;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cube root function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::CubeRoot()
|
||||
{
|
||||
return new RealNumber(cbrt(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reciprocal function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Reciprocal()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(1.0 / static_cast<double>(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Factorial function.
|
||||
*
|
||||
*/
|
||||
Number* IntegerNumber::Factorial()
|
||||
{
|
||||
if (i < 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (i == 0 || i == 1)
|
||||
return new IntegerNumber(1);
|
||||
|
||||
int l = i > 1000 ? 1000 : i;
|
||||
double r = 1.0;
|
||||
|
||||
for (int c = 1; c <= l; c++)
|
||||
r = r * c;
|
||||
|
||||
if (r < static_cast<double>(MAX_INT_NUM))
|
||||
return new IntegerNumber(static_cast<int>(r));
|
||||
|
||||
return new RealNumber(r);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Binary logarithm function (base 2).
|
||||
*
|
||||
* See implementation of natural logarithm in log(double)
|
||||
*/
|
||||
Number* IntegerNumber::Log2()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (i > 0)
|
||||
return new RealNumber(log(static_cast<double>(i)) / LOG2);
|
||||
|
||||
Number* n = new ComplexNumber(static_cast<double>(i), 0);
|
||||
Number* r = n->Log2();
|
||||
delete n;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Natural logarithm function (base e).
|
||||
*
|
||||
* See implementation of natural logarithm in log(double)
|
||||
*/
|
||||
Number* IntegerNumber::Log()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (i > 0)
|
||||
return new RealNumber(log(static_cast<double>(i)));
|
||||
|
||||
Number* n = new ComplexNumber(static_cast<double>(i), 0);
|
||||
Number* r = n->Log();
|
||||
delete n;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base 10 logarithm function.
|
||||
*
|
||||
* See implementation of base 10 logarithm in log10(double)
|
||||
*/
|
||||
Number* IntegerNumber::Log10()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
if (i > 0)
|
||||
return new RealNumber(log10(static_cast<double>(i)));
|
||||
|
||||
Number* n = new ComplexNumber(static_cast<double>(i), 0);
|
||||
Number* r = n->Log10();
|
||||
delete n;
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trigonometric cosine function.
|
||||
*
|
||||
* See implementation of cosine function in cos(double)
|
||||
*/
|
||||
Number* IntegerNumber::Cosine()
|
||||
{
|
||||
return new RealNumber(cos(static_cast<double>(i)), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trigonometric secant function.
|
||||
*
|
||||
* See implementation of cosine function in cos(double)
|
||||
*/
|
||||
Number* IntegerNumber::Secant()
|
||||
{
|
||||
double a = cos(static_cast<double>(i));
|
||||
|
||||
if (a == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(1.0 / a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trigonometric tangent function.
|
||||
*
|
||||
* See implementation of tangent function in tan(double)
|
||||
*/
|
||||
Number* IntegerNumber::Tangent()
|
||||
{
|
||||
return new RealNumber(tan(static_cast<double>(i)), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trigonometric cotangent function.
|
||||
*
|
||||
* See implementation of tangent function in tan(double)
|
||||
*/
|
||||
Number* IntegerNumber::Cotangent()
|
||||
{
|
||||
double a = tan(static_cast<double>(i));
|
||||
|
||||
if (a == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(1.0 / a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic sine function.
|
||||
*
|
||||
* See implementation of hyperbolic sine function in sinh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypSine()
|
||||
{
|
||||
return new RealNumber(sinh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic cosecant function.
|
||||
*
|
||||
* See implementation of hyperbolic sine function in sinh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypCosecant()
|
||||
{
|
||||
double a = sinh(static_cast<double>(i));
|
||||
|
||||
if (a == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(1.0 / a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic cosine function.
|
||||
*
|
||||
* See implementation of hyperbolic cosine function in cosh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypCosine()
|
||||
{
|
||||
return new RealNumber(cosh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic secant function.
|
||||
*
|
||||
* See implementation of hyperbolic cosine function in cosh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypSecant()
|
||||
{
|
||||
return new RealNumber(1.0 / cosh(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic tangent function.
|
||||
*
|
||||
* See implementation of hyperbolic tangent function in tanh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypTangent()
|
||||
{
|
||||
return new RealNumber(tanh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Hyperbolic cotangent function.
|
||||
*
|
||||
* See implementation of hyperbolic tangent function in tanh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypCotangent()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(1.0 / tanh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trigonometric sine function.
|
||||
*
|
||||
* See implementation of sine function in sin(double)
|
||||
*/
|
||||
Number* IntegerNumber::Sine()
|
||||
{
|
||||
return new RealNumber(sin(static_cast<double>(i)), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trigonometric cosecant function.
|
||||
*
|
||||
* See implementation of sine function in sin(double)
|
||||
*/
|
||||
Number* IntegerNumber::Cosecant()
|
||||
{
|
||||
double a = sin(static_cast<double>(i));
|
||||
|
||||
if (a == 0.0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(1.0 / a);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse trigonometric cosine function.
|
||||
*
|
||||
* See implementation of inverse trigonometric cosine in acos(double)
|
||||
*/
|
||||
Number* IntegerNumber::ArcCosine()
|
||||
{
|
||||
return new RealNumber(acos(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse trigonometric secant function.
|
||||
*
|
||||
* See implementation of inverse trigonometric cosine in acos(double)
|
||||
*/
|
||||
Number* IntegerNumber::ArcSecant()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(acos(1.0 / static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse trigonometric tangent function.
|
||||
*
|
||||
* See implementation of inverse trigonometric tangent in atan(double)
|
||||
*/
|
||||
Number* IntegerNumber::ArcTangent()
|
||||
{
|
||||
return new RealNumber(atan(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse trigonometric cotangent function.
|
||||
*
|
||||
* See implementation of inverse trigonometric tangent in atan(double)
|
||||
*/
|
||||
Number* IntegerNumber::ArcCotangent()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(atan(1.0 / static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse trigonometric sine function.
|
||||
*
|
||||
* See implementation of inverse trigonometric sine in asin(double)
|
||||
*/
|
||||
Number* IntegerNumber::ArcSine()
|
||||
{
|
||||
return new RealNumber(asin(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse trigonometric cosecant function.
|
||||
*
|
||||
* See implementation of inverse trigonometric sine in asin(double)
|
||||
*/
|
||||
Number* IntegerNumber::ArcCosecant()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(asin(1.0 / static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic cosine function.
|
||||
*
|
||||
* See implementation of inverse hyperbolic cosine in acosh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypArcCosine()
|
||||
{
|
||||
return new RealNumber(acosh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic secant function.
|
||||
*
|
||||
* See implementation of inverse hyperbolic cosine in acosh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypArcSecant()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(acosh(1.0 / static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic sine function.
|
||||
*
|
||||
* See implementation of inverse hyperbolic sine in asinh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypArcSine()
|
||||
{
|
||||
return new RealNumber(asinh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic cosecant function.
|
||||
*
|
||||
* See implementation of inverse hyperbolic sine in asinh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypArcCosecant()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(asinh(1.0 / static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic tangent function.
|
||||
*
|
||||
* See implementation hyperbolic tangent in atanh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypArcTangent()
|
||||
{
|
||||
return new RealNumber(atanh(static_cast<double>(i)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Inverse hyperbolic cotangent function.
|
||||
*
|
||||
* See implementation hyperbolic tangent in atanh(double)
|
||||
*/
|
||||
Number* IntegerNumber::HypArcCotangent()
|
||||
{
|
||||
if (i == 0)
|
||||
return new NonNumber(nnnan);
|
||||
|
||||
return new RealNumber(atanh(1.0 / static_cast<double>(i)));
|
||||
}
|
||||
|
||||
Number* IntegerNumber::VerSine()
|
||||
{
|
||||
return new RealNumber(1.0 - cos((double)i), true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::VerCosine()
|
||||
{
|
||||
return new RealNumber(1.0 + cos((double)i), true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::CoVerSine()
|
||||
{
|
||||
return new RealNumber(1.0 - sin((double)i), true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::CoVerCosine()
|
||||
{
|
||||
return new RealNumber(1.0 + sin((double)i), true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::HaVerSine()
|
||||
{
|
||||
return new RealNumber((1.0 - cos((double)i)) / 2.0, true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::HaVerCosine()
|
||||
{
|
||||
return new RealNumber((1.0 + cos((double)i)) / 2.0, true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::HaCoVerSine()
|
||||
{
|
||||
return new RealNumber((1.0 - sin((double)i)) / 2.0, true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::HaCoVerCosine()
|
||||
{
|
||||
return new RealNumber((1.0 + sin((double)i)) / 2.0, true);
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcVerSine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcVerSine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcVerCosine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcVerCosine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcCoVerSine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcCoVerSine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcCoVerCosine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcCoVerCosine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcHaVerSine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcHaVerSine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcHaVerCosine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcHaVerCosine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcHaCoVerSine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcHaCoVerSine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcHaCoVerCosine()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcHaCoVerCosine();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ExSecant()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ExSecant();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ExCosecant()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ExCosecant();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcExSecant()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcExSecant();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
|
||||
Number* IntegerNumber::ArcExCosecant()
|
||||
{
|
||||
Number* n = new RealNumber(static_cast<double>(i));
|
||||
Number* x = n->ArcExCosecant();
|
||||
delete n;
|
||||
return x;
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_INTEGER_NUMBER_H
|
||||
#define AMATH_INTEGER_NUMBER_H
|
||||
|
||||
/**
|
||||
* @file integer.h
|
||||
* @brief Class based handling of integer numbers.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "numb.h"
|
||||
|
||||
#define MAX_INT_NUM 0x7fffffff
|
||||
|
||||
/**
|
||||
* @brief Represent a integer number.
|
||||
*
|
||||
*/
|
||||
struct IntegerNumber : public Number
|
||||
{
|
||||
public:
|
||||
IntegerNumber();
|
||||
explicit IntegerNumber(signed int i);
|
||||
explicit IntegerNumber(unsigned int i);
|
||||
~IntegerNumber();
|
||||
|
||||
Number* Clone();
|
||||
int GetIntegerValue();
|
||||
double GetRealValue();
|
||||
bool PureComplexValue();
|
||||
int GetPrecedence();
|
||||
int GetDefaultPrecedence();
|
||||
bool IsZero();
|
||||
bool IsNaN();
|
||||
bool IsTooSmall();
|
||||
bool IsTooLarge();
|
||||
bool IsNotImplemented();
|
||||
|
||||
Number* Unary();
|
||||
Number* Add(Number* other);
|
||||
Number* Sub(Number* other);
|
||||
Number* Mul(Number* other);
|
||||
Number* Div(Number* other);
|
||||
Number* Raise(Number* exponent);
|
||||
|
||||
Number* Signum();
|
||||
Number* Trunc();
|
||||
Number* Round();
|
||||
Number* Floor();
|
||||
Number* Ceiling();
|
||||
Number* Absolute();
|
||||
Number* SquareRoot();
|
||||
Number* CubeRoot();
|
||||
Number* Reciprocal();
|
||||
Number* Factorial();
|
||||
|
||||
Number* Log();
|
||||
Number* Log2();
|
||||
Number* Log10();
|
||||
|
||||
Number* Sine();
|
||||
Number* Cosine();
|
||||
Number* Tangent();
|
||||
Number* Cosecant();
|
||||
Number* Secant();
|
||||
Number* Cotangent();
|
||||
Number* ArcSine();
|
||||
Number* ArcCosine();
|
||||
Number* ArcTangent();
|
||||
Number* ArcCosecant();
|
||||
Number* ArcSecant();
|
||||
Number* ArcCotangent();
|
||||
|
||||
Number* HypSine();
|
||||
Number* HypCosine();
|
||||
Number* HypTangent();
|
||||
Number* HypCosecant();
|
||||
Number* HypSecant();
|
||||
Number* HypCotangent();
|
||||
Number* HypArcSine();
|
||||
Number* HypArcCosine();
|
||||
Number* HypArcTangent();
|
||||
Number* HypArcCosecant();
|
||||
Number* HypArcSecant();
|
||||
Number* HypArcCotangent();
|
||||
|
||||
Number* VerSine();
|
||||
Number* VerCosine();
|
||||
Number* CoVerSine();
|
||||
Number* CoVerCosine();
|
||||
Number* HaVerSine();
|
||||
Number* HaVerCosine();
|
||||
Number* HaCoVerSine();
|
||||
Number* HaCoVerCosine();
|
||||
|
||||
Number* ArcVerSine();
|
||||
Number* ArcVerCosine();
|
||||
Number* ArcCoVerSine();
|
||||
Number* ArcCoVerCosine();
|
||||
Number* ArcHaVerSine();
|
||||
Number* ArcHaVerCosine();
|
||||
Number* ArcHaCoVerSine();
|
||||
Number* ArcHaCoVerCosine();
|
||||
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
|
||||
friend struct RealNumber;
|
||||
friend struct ComplexNumber;
|
||||
|
||||
private:
|
||||
signed int i;
|
||||
};
|
||||
|
||||
#endif
|
||||
+20
-10
@@ -70,26 +70,26 @@ int NonNumber::GetDefaultPrecedence()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool NonNumber::IsNegative()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NonNumber::IsZero()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NonNumber::IsTooSmall()
|
||||
{
|
||||
return type == nnninf;
|
||||
}
|
||||
|
||||
bool NonNumber::IsTooLarge()
|
||||
{
|
||||
return type == nninf;
|
||||
}
|
||||
|
||||
bool NonNumber::IsNaN()
|
||||
{
|
||||
return type == nnnan;
|
||||
}
|
||||
|
||||
bool NonNumber::IsInfinite()
|
||||
{
|
||||
return type == nnninf;
|
||||
}
|
||||
|
||||
bool NonNumber::IsNotImplemented()
|
||||
{
|
||||
return type == nnnimp;
|
||||
@@ -219,6 +219,11 @@ Number* NonNumber::Cotangent()
|
||||
return new NonNumber(type);
|
||||
}
|
||||
|
||||
Number *NonNumber::Chord()
|
||||
{
|
||||
return new NonNumber(type);
|
||||
}
|
||||
|
||||
Number* NonNumber::HypSine()
|
||||
{
|
||||
return new NonNumber(type);
|
||||
@@ -289,6 +294,11 @@ Number* NonNumber::ArcCosecant()
|
||||
return new NonNumber(type);
|
||||
}
|
||||
|
||||
Number *NonNumber::ArcChord()
|
||||
{
|
||||
return new NonNumber(type);
|
||||
}
|
||||
|
||||
Number* NonNumber::HypArcCosine()
|
||||
{
|
||||
return new NonNumber(type);
|
||||
|
||||
+10
-11
@@ -32,8 +32,7 @@
|
||||
|
||||
/**
|
||||
* @file nnumb.h
|
||||
* @brief Class based handling of Infinity and Not A Number.
|
||||
*
|
||||
* @brief Class based handling of Infinity and Not A Number
|
||||
*/
|
||||
|
||||
#include "numb.h"
|
||||
@@ -47,8 +46,7 @@ typedef enum
|
||||
} NonNumberType;
|
||||
|
||||
/**
|
||||
* @brief Represent a number which does not exists.
|
||||
*
|
||||
* @brief Represent a number which does not exists
|
||||
*/
|
||||
struct NonNumber : public Number
|
||||
{
|
||||
@@ -62,10 +60,10 @@ public:
|
||||
bool PureComplexValue();
|
||||
int GetPrecedence();
|
||||
int GetDefaultPrecedence();
|
||||
bool IsNegative();
|
||||
bool IsZero();
|
||||
bool IsNaN();
|
||||
bool IsTooSmall();
|
||||
bool IsTooLarge();
|
||||
bool IsInfinite();
|
||||
bool IsNotImplemented();
|
||||
|
||||
Number* Unary();
|
||||
@@ -96,12 +94,18 @@ public:
|
||||
Number* Cosecant();
|
||||
Number* Secant();
|
||||
Number* Cotangent();
|
||||
Number* Chord();
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcSine();
|
||||
Number* ArcCosine();
|
||||
Number* ArcTangent();
|
||||
Number* ArcCosecant();
|
||||
Number* ArcSecant();
|
||||
Number* ArcCotangent();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
Number* ArcChord();
|
||||
|
||||
Number* HypSine();
|
||||
Number* HypCosine();
|
||||
@@ -134,11 +138,6 @@ public:
|
||||
Number* ArcHaCoVerSine();
|
||||
Number* ArcHaCoVerCosine();
|
||||
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
|
||||
private:
|
||||
NonNumberType type;
|
||||
};
|
||||
|
||||
+2
-422
@@ -27,18 +27,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "amath.h"
|
||||
#include "amathc.h"
|
||||
#include "math.h"
|
||||
#include "complex.h"
|
||||
#include "real.h"
|
||||
#include "cplex.h"
|
||||
#include "ntext.h"
|
||||
#include "integer.h"
|
||||
#include "charbuf.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
NumeralSystem::NumeralSystem()
|
||||
{
|
||||
buf = new CharBuffer();
|
||||
@@ -50,420 +41,9 @@ NumeralSystem::~NumeralSystem()
|
||||
delete buf;
|
||||
}
|
||||
|
||||
Number* NumeralSystem::Parse(const char* text)
|
||||
Number *NumeralSystem::Parse(const char *text)
|
||||
{
|
||||
unsigned int length;
|
||||
char* end;
|
||||
char *end;
|
||||
return Parse(text, &length, &end);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
PositionalNumeralSystem::PositionalNumeralSystem(
|
||||
unsigned int base,
|
||||
unsigned int digits,
|
||||
const char fractionpoint) :
|
||||
base(base * 1.0), digits(digits)
|
||||
{
|
||||
this->fractionpoint = fractionpoint;
|
||||
}
|
||||
|
||||
PositionalNumeralSystem::~PositionalNumeralSystem()
|
||||
{
|
||||
}
|
||||
|
||||
const char* PositionalNumeralSystem::GetName()
|
||||
{
|
||||
switch (static_cast<int>(base))
|
||||
{
|
||||
case 2:
|
||||
return "binary";
|
||||
case 8:
|
||||
return "octal";
|
||||
case 10:
|
||||
return "decimal";
|
||||
case 16:
|
||||
return "hexadecimal";
|
||||
}
|
||||
|
||||
const char* text = "base ";
|
||||
Number* n = new RealNumber(base);
|
||||
NumeralSystem* ns = new DecimalSystem(2);
|
||||
const char* numtext = ns->GetText(n);
|
||||
|
||||
buf->EnsureSize(StrLen(text) + StrLen(numtext) + 1);
|
||||
buf->Empty();
|
||||
buf->Append(text);
|
||||
buf->Append(numtext);
|
||||
|
||||
delete ns;
|
||||
delete n;
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
const char* PositionalNumeralSystem::GetPrefix()
|
||||
{
|
||||
// TODO: Implement
|
||||
return "";
|
||||
}
|
||||
|
||||
unsigned int PositionalNumeralSystem::GetDigits()
|
||||
{
|
||||
return digits;
|
||||
}
|
||||
|
||||
void PositionalNumeralSystem::SetDigits(unsigned int digits)
|
||||
{
|
||||
this->digits = digits;
|
||||
}
|
||||
|
||||
const char PositionalNumeralSystem::GetFractionPoint()
|
||||
{
|
||||
return static_cast<const char>(this->fractionpoint);
|
||||
}
|
||||
|
||||
void PositionalNumeralSystem::SetFractionPoint(const char fractionpoint)
|
||||
{
|
||||
this->fractionpoint = fractionpoint;
|
||||
}
|
||||
|
||||
const char* PositionalNumeralSystem::GetText(Number* number)
|
||||
{
|
||||
if (number->IsNaN())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("NaN");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsNotImplemented())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("NotImplemented");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsTooSmall())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("-Inf");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsTooLarge())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("Inf");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->system == nsysinteger)
|
||||
{
|
||||
return GetText(number->GetRealValue()); // TODO: Optimize
|
||||
}
|
||||
|
||||
if (number->system == nsysreal)
|
||||
{
|
||||
return GetText(number->GetRealValue());
|
||||
}
|
||||
|
||||
complex w = static_cast<ComplexNumber*>(number)->GetComplexValue();
|
||||
double a = creal(w);
|
||||
double b = cimag(w);
|
||||
|
||||
if (a == 0.0 && b == 0.0)
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append('0');
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
CharBuffer* val = new CharBuffer(512);
|
||||
val->Empty();
|
||||
|
||||
if (a != 0.0)
|
||||
{
|
||||
const char* real = GetText(a);
|
||||
val->Append(real);
|
||||
}
|
||||
|
||||
const char* imag = GetText(b);
|
||||
if (a != 0.0 && b > 0.0)
|
||||
{
|
||||
val->Append('+');
|
||||
}
|
||||
|
||||
if (b != 0.0)
|
||||
{
|
||||
val->Append(imag);
|
||||
val->Append('i');
|
||||
}
|
||||
|
||||
buf->Copy(val);
|
||||
delete val;
|
||||
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
const char* PositionalNumeralSystem::GetText(double number) const
|
||||
{
|
||||
if (!finite(number))
|
||||
{
|
||||
return "Inf";
|
||||
}
|
||||
else if (isnan(number))
|
||||
{
|
||||
return "NaN";
|
||||
}
|
||||
else if (number == 0.0)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
buf->Empty();
|
||||
|
||||
double dnumber = number;
|
||||
if (dnumber < 0.0)
|
||||
{
|
||||
buf->Append('-');
|
||||
dnumber = -dnumber;
|
||||
}
|
||||
|
||||
double expbor = log2p(base, dnumber);
|
||||
double expacc = expbor > 0.0 ? 4e-14 : -1e-15;
|
||||
double expborder = trunc(expbor + expacc);
|
||||
|
||||
int exponent = 0;
|
||||
double rounding;
|
||||
|
||||
double bordermax = trunc(9.0 * 10 / base);
|
||||
double bordermin = trunc(-8.0 * 10 / base);
|
||||
|
||||
// Find exponent
|
||||
if (expborder >= bordermax || expborder <= bordermin)
|
||||
{
|
||||
double dexp = trunc(log2p(base, dnumber) + expacc);
|
||||
dnumber = dnumber * pow(base, -dexp);
|
||||
|
||||
// pow is inaccurate on small and large numbers
|
||||
if (dexp > 15 || dexp < -15)
|
||||
{
|
||||
dnumber += 2e-15;
|
||||
}
|
||||
|
||||
// Adjust if below zero
|
||||
if (dnumber < 1.0)
|
||||
{
|
||||
dexp--;
|
||||
dnumber *= base;
|
||||
}
|
||||
|
||||
exponent = static_cast<int>(dexp);
|
||||
rounding = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
double acc = exponent > 0 ? 15 : -15;
|
||||
rounding = pow(base, exponent + acc);
|
||||
}
|
||||
|
||||
int digitout;
|
||||
int intdigits;
|
||||
|
||||
double intvalue = trunc(dnumber + rounding);
|
||||
IntegerToBuffer(intvalue, digits, &intdigits);
|
||||
|
||||
int fragdigits = digits - intdigits + (intvalue < 1.0 ? 1 : 0);
|
||||
if (fragdigits > 0)
|
||||
{
|
||||
buf->Append(fractionpoint);
|
||||
|
||||
double fraction = fabs(round((dnumber - intvalue) * pow(base, fragdigits)));
|
||||
|
||||
double temp1 = log2p(base, fraction);
|
||||
int fin = finite(temp1);
|
||||
int actualdigits = static_cast<int>(trunc(temp1 + 3e-15));
|
||||
int padding = fragdigits - (fin == 1 ? actualdigits : 0) - 1;
|
||||
|
||||
// Pad zeros if needed
|
||||
while (padding-- > 0)
|
||||
{
|
||||
buf->Append('0');
|
||||
}
|
||||
|
||||
intvalue = static_cast<int64_t>(trunc(fraction * base) / base);
|
||||
IntegerToBuffer(intvalue, fragdigits, &digitout);
|
||||
|
||||
// Remove trailing zeros
|
||||
// ReSharper disable once CppPossiblyErroneousEmptyStatements
|
||||
while (buf->RemoveTrailing('0'));
|
||||
|
||||
buf->RemoveTrailing(fractionpoint);
|
||||
}
|
||||
|
||||
// Add exponent
|
||||
if (exponent != 0)
|
||||
{
|
||||
buf->Append('e');
|
||||
buf->Append(exponent > 0 ? '+' : '-');
|
||||
IntegerToBuffer(abs(exponent), 3, &digitout);
|
||||
}
|
||||
|
||||
// Make sure no rounding error is returned
|
||||
if (buf->Is("-0"))
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append('0');
|
||||
}
|
||||
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
void PositionalNumeralSystem::IntegerToBuffer(double value, unsigned int digits, int* outdigits) const
|
||||
{
|
||||
static const char* alphaNumerics = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
unsigned int count = 0;
|
||||
char* chars = new char[128];
|
||||
char* start = chars;
|
||||
|
||||
do
|
||||
{
|
||||
count++;
|
||||
unsigned int intremainder = static_cast<unsigned int>(trunc(fmod(value, base)));
|
||||
*chars++ = alphaNumerics[intremainder];
|
||||
value /= base;
|
||||
}
|
||||
while (value >= 1.0);
|
||||
|
||||
unsigned int n = count;
|
||||
unsigned int q = digits;
|
||||
chars--;
|
||||
|
||||
while (n-- != 0 && q-- != 0)
|
||||
{
|
||||
buf->Append(*chars--);
|
||||
}
|
||||
|
||||
n++;
|
||||
while (n-- != 0)
|
||||
{
|
||||
buf->Append('0');
|
||||
}
|
||||
|
||||
*outdigits = count;
|
||||
delete [] start;
|
||||
}
|
||||
|
||||
Number* PositionalNumeralSystem::Parse(const char* text, unsigned int* length, char** end)
|
||||
{
|
||||
unsigned int intbase = static_cast<unsigned int>(base);
|
||||
char maxNumeric = (intbase > 10 ? 10 : intbase) + '0' - 1;
|
||||
char maxAlpha = intbase > 10 ? intbase + 'A' - 11 : 0;
|
||||
|
||||
unsigned int pos = 0;
|
||||
double integer = 0;
|
||||
double addition;
|
||||
|
||||
while (*text != '\0' && ((*text >= '0' && *text <= maxNumeric) || (maxAlpha != 0 && *text >= 'A' && *text <= maxAlpha)))
|
||||
{
|
||||
addition = ((*text >= '0' && *text <= maxNumeric) ? (*text - '0') : (*text - 'A' + 10)) * 1.0;
|
||||
integer = integer * base + addition;
|
||||
text++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Digits not found
|
||||
if (pos == 0)
|
||||
{
|
||||
*length = 0;
|
||||
*end = const_cast<char*>(text);
|
||||
return new RealNumber();
|
||||
}
|
||||
|
||||
double fraction = 0.0;
|
||||
double divisor = 1.0;
|
||||
if (*text == fractionpoint && fractionpoint != '\0')
|
||||
{
|
||||
text++;
|
||||
pos++;
|
||||
|
||||
while (*text != '\0' && ((*text >= '0' && *text <= maxNumeric) || (maxAlpha != '\0' && *text >= 'A' && *text <= maxAlpha)))
|
||||
{
|
||||
addition = ((*text >= '0' && *text <= maxNumeric) ? (*text - '0') : (*text - 'A' + 10));
|
||||
fraction = fraction * base + addition;
|
||||
divisor *= base;
|
||||
text++;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
double exp = 0.0;
|
||||
if (*text == 'e' || *text == 'E')
|
||||
{
|
||||
text++;
|
||||
pos++;
|
||||
|
||||
double sign = *text == '+' ? 1.0 : *text == '-' ? -1.0 : 0.0;
|
||||
|
||||
if (sign != 0.0)
|
||||
{
|
||||
text++;
|
||||
pos++;
|
||||
|
||||
while (*text != '\0' && ((*text >= '0' && *text <= maxNumeric) || (maxAlpha != 0 && *text >= 'A' && *text <= maxAlpha)))
|
||||
{
|
||||
addition = ((*text >= '0' && *text <= maxNumeric) ? (*text - '0') : (*text - 'A' + 10)) * 1.0;
|
||||
exp = exp * base + addition;
|
||||
text++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
exp *= sign;
|
||||
}
|
||||
else
|
||||
{
|
||||
text--;
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
|
||||
*length = pos;
|
||||
*end = const_cast<char*>(text);
|
||||
|
||||
if (integer >= static_cast<double>(MAX_INT_NUM) && fraction == 0.0 && exp == 0.0)
|
||||
return new IntegerNumber(static_cast<int>(integer));
|
||||
|
||||
|
||||
double dnumber = (integer + (fraction / divisor));
|
||||
|
||||
if (exp != 0.0)
|
||||
{
|
||||
// pow seems a bit off
|
||||
dnumber *= pow(base, exp + 4e-15);
|
||||
}
|
||||
|
||||
return new RealNumber(dnumber);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
DecimalSystem::DecimalSystem() :
|
||||
PositionalNumeralSystem(10, 5, '\0')
|
||||
{
|
||||
}
|
||||
|
||||
DecimalSystem::DecimalSystem(unsigned int digits) :
|
||||
PositionalNumeralSystem(10, digits, '\0')
|
||||
{
|
||||
}
|
||||
|
||||
DecimalSystem::DecimalSystem(
|
||||
unsigned int digits,
|
||||
const char fractionpoint) :
|
||||
PositionalNumeralSystem(10, digits, fractionpoint)
|
||||
{
|
||||
}
|
||||
|
||||
DecimalSystem::~DecimalSystem()
|
||||
{
|
||||
}
|
||||
|
||||
+4
-48
@@ -32,21 +32,19 @@
|
||||
|
||||
/**
|
||||
* @file ntext.h
|
||||
* @brief Text to numbers handling.
|
||||
* @brief Text to numbers handling
|
||||
* @details
|
||||
* Converts both between text and numbers AND between numbers and text.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "numb.h"
|
||||
#include "charbuf.h"
|
||||
|
||||
/**
|
||||
* @brief Base class for all numeral systems.
|
||||
* @brief Base class for all numeral systems
|
||||
* @details
|
||||
* More info on numeral systems is available at [Wikipedia]:
|
||||
* More info on numeral systems is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Numeral_system
|
||||
*
|
||||
*/
|
||||
class NumeralSystem
|
||||
{
|
||||
@@ -58,7 +56,7 @@ public:
|
||||
virtual unsigned int GetDigits() = 0;
|
||||
virtual void SetDigits(unsigned int digits) = 0;
|
||||
virtual const char GetFractionPoint() = 0;
|
||||
virtual void SetFractionPoint(const char fractionpoint) = 0;
|
||||
virtual void SetFractionPoint(const char fractionPoint) = 0;
|
||||
virtual const char* GetText(Number* number) = 0;
|
||||
virtual Number* Parse(const char* text, unsigned int* length, char** end) = 0;
|
||||
virtual Number* Parse(const char* text);
|
||||
@@ -67,46 +65,4 @@ protected:
|
||||
CharBuffer* buf;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base class for all numeral systems with a
|
||||
* positional notation.
|
||||
* @details
|
||||
* More info on positional notation is available at [Wikipedia]:
|
||||
* https://wikipedia.org/wiki/Positional_notation
|
||||
*
|
||||
*/
|
||||
class PositionalNumeralSystem : public NumeralSystem
|
||||
{
|
||||
public:
|
||||
PositionalNumeralSystem(unsigned int base, unsigned int digits, const char fractionpoint);
|
||||
~PositionalNumeralSystem();
|
||||
|
||||
virtual const char* GetName();
|
||||
virtual const char* GetPrefix();
|
||||
virtual unsigned int GetDigits();
|
||||
virtual void SetDigits(unsigned int digits);
|
||||
virtual const char GetFractionPoint();
|
||||
virtual void SetFractionPoint(const char fractionpoint);
|
||||
virtual const char* GetText(Number* number);
|
||||
virtual Number* Parse(const char* text, unsigned int* length, char** end);
|
||||
|
||||
protected:
|
||||
double base;
|
||||
unsigned int digits;
|
||||
char fractionpoint;
|
||||
|
||||
private:
|
||||
const char* GetText(double number) const;
|
||||
void IntegerToBuffer(double value, unsigned int digits, int* outdigits) const;
|
||||
};
|
||||
|
||||
class DecimalSystem : public PositionalNumeralSystem
|
||||
{
|
||||
public:
|
||||
DecimalSystem();
|
||||
DecimalSystem(unsigned int digits, const char fractionpoint);
|
||||
explicit DecimalSystem(unsigned int digits);
|
||||
~DecimalSystem();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2014 Ryan Juckett
|
||||
* http://www.ryanjuckett.com/
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not
|
||||
* be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
|
||||
#include "ntextd.h"
|
||||
#include "bigint.h"
|
||||
#include "amathc.h"
|
||||
#include "amath.h"
|
||||
#include "mathr.h"
|
||||
#include "mathi.h"
|
||||
#include "cplex.h"
|
||||
|
||||
DecimalSystem::DecimalSystem() : PositionalNumeralSystem(10, 5, '\0')
|
||||
{
|
||||
}
|
||||
|
||||
DecimalSystem::DecimalSystem(unsigned int digits) :
|
||||
PositionalNumeralSystem(10, digits, '\0')
|
||||
{
|
||||
}
|
||||
|
||||
DecimalSystem::DecimalSystem(unsigned int digits, const char fractionPoint) :
|
||||
PositionalNumeralSystem(10, digits, fractionPoint)
|
||||
{
|
||||
}
|
||||
|
||||
DecimalSystem::~DecimalSystem()
|
||||
{
|
||||
}
|
||||
|
||||
const char *DecimalSystem::GetText(Number *number)
|
||||
{
|
||||
const char *sc = GetSpecialCase(number);
|
||||
if (sc != nullptr)
|
||||
{
|
||||
return sc;
|
||||
}
|
||||
|
||||
if (number->system == nsysreal)
|
||||
{
|
||||
buf->Empty();
|
||||
return GetText(number->GetRealValue());
|
||||
}
|
||||
|
||||
complex w = ((ComplexNumber *)number)->GetComplexValue();
|
||||
double a = creal(w);
|
||||
double b = cimag(w);
|
||||
|
||||
buf->Empty();
|
||||
if (a != 0.0)
|
||||
{
|
||||
GetText(a);
|
||||
}
|
||||
|
||||
if (a != 0.0 && b > 0.0)
|
||||
{
|
||||
buf->Append('+');
|
||||
}
|
||||
|
||||
if (b != 0.0)
|
||||
{
|
||||
GetText(b);
|
||||
buf->Append('i');
|
||||
}
|
||||
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
const char *DecimalSystem::GetText(double number) const
|
||||
{
|
||||
int32_t printExponent = 0;
|
||||
double dexponent = log10(fabs(number));
|
||||
int32_t precision = digits - (int32_t)trunc(dexponent) - 1;
|
||||
int32_t lim = 15;
|
||||
bool sci = (dexponent > 9.0 || dexponent < -8.0);
|
||||
if (sci)
|
||||
{
|
||||
precision = digits;
|
||||
}
|
||||
else if (dexponent < 0.0)
|
||||
{
|
||||
precision++;
|
||||
lim--;
|
||||
}
|
||||
|
||||
if (precision > lim)
|
||||
{
|
||||
precision = lim;
|
||||
}
|
||||
|
||||
static const int size = 64;
|
||||
char *out = new char[size];
|
||||
char *pOutBuffer = out;
|
||||
uint32_t bufferSize = size;
|
||||
|
||||
FloatUnion64 floatUnion;
|
||||
floatUnion.floatingPoint = number;
|
||||
uint32_t floatExponent = floatUnion.GetExponent();
|
||||
uint64_t floatMantissa = floatUnion.GetMantissa();
|
||||
|
||||
if (floatUnion.IsNegative())
|
||||
{
|
||||
pOutBuffer[0] = '-';
|
||||
++pOutBuffer;
|
||||
--bufferSize;
|
||||
}
|
||||
|
||||
uint64_t mantissa;
|
||||
int32_t exponent;
|
||||
uint32_t mantissaHighBitIdx;
|
||||
bool hasUnequalMargins;
|
||||
|
||||
if (floatExponent != 0)
|
||||
{
|
||||
// normal
|
||||
mantissa = (1ull << 52) | floatMantissa;
|
||||
exponent = floatExponent - 1023 - 52;
|
||||
mantissaHighBitIdx = 52;
|
||||
hasUnequalMargins = (floatExponent != 1) && (floatMantissa == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// subnormal
|
||||
mantissa = floatMantissa;
|
||||
exponent = 1 - 1023 - 52;
|
||||
mantissaHighBitIdx = log2i(mantissa);
|
||||
hasUnequalMargins = false;
|
||||
}
|
||||
|
||||
if (!sci)
|
||||
{
|
||||
int32_t printExponent;
|
||||
uint32_t numPrintDigits;
|
||||
uint32_t maxPrintLen = bufferSize - 1;
|
||||
numPrintDigits = Dragon4(mantissa,
|
||||
exponent,
|
||||
mantissaHighBitIdx,
|
||||
hasUnequalMargins,
|
||||
CutoffMode_FractionLength,
|
||||
precision,
|
||||
pOutBuffer,
|
||||
maxPrintLen,
|
||||
&printExponent);
|
||||
|
||||
// track the number of digits past the decimal point that have been printed
|
||||
uint32_t numFractionDigits = 0;
|
||||
|
||||
// if output has a whole number
|
||||
if (printExponent >= 0)
|
||||
{
|
||||
// leave the whole number at the start of the buffer
|
||||
uint32_t numWholeDigits = printExponent + 1;
|
||||
if (numPrintDigits < numWholeDigits)
|
||||
{
|
||||
// don't overflow the buffer
|
||||
if (numWholeDigits > maxPrintLen)
|
||||
numWholeDigits = maxPrintLen;
|
||||
|
||||
// add trailing zeros up to the decimal point
|
||||
for (; numPrintDigits < numWholeDigits; ++numPrintDigits)
|
||||
pOutBuffer[numPrintDigits] = '0';
|
||||
}
|
||||
// insert the decimal point prior to the fraction
|
||||
else if (numPrintDigits > (uint32_t)numWholeDigits)
|
||||
{
|
||||
numFractionDigits = numPrintDigits - numWholeDigits;
|
||||
uint32_t maxFractionDigits = maxPrintLen - numWholeDigits - 1;
|
||||
if (numFractionDigits > maxFractionDigits)
|
||||
numFractionDigits = maxFractionDigits;
|
||||
|
||||
MemCopy(pOutBuffer + numWholeDigits + 1, pOutBuffer + numWholeDigits, numFractionDigits);
|
||||
pOutBuffer[numWholeDigits] = fractionPoint;
|
||||
numPrintDigits = numWholeDigits + 1 + numFractionDigits;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// shift out the fraction to make room for the leading zeros
|
||||
if (maxPrintLen > 2)
|
||||
{
|
||||
uint32_t numFractionZeros = (uint32_t)-printExponent - 1;
|
||||
uint32_t maxFractionZeros = maxPrintLen - 2;
|
||||
if (numFractionZeros > maxFractionZeros)
|
||||
numFractionZeros = maxFractionZeros;
|
||||
|
||||
uint32_t digitsStartIdx = 2 + numFractionZeros;
|
||||
|
||||
// shift the significant digits right such that there is room for leading zeros
|
||||
numFractionDigits = numPrintDigits;
|
||||
uint32_t maxFractionDigits = maxPrintLen - digitsStartIdx;
|
||||
if (numFractionDigits > maxFractionDigits)
|
||||
numFractionDigits = maxFractionDigits;
|
||||
|
||||
MemCopy(pOutBuffer + digitsStartIdx, pOutBuffer, numFractionDigits);
|
||||
|
||||
// insert the leading zeros
|
||||
for (uint32_t i = 2; i < digitsStartIdx; ++i)
|
||||
pOutBuffer[i] = '0';
|
||||
|
||||
// update the counts
|
||||
numFractionDigits += numFractionZeros;
|
||||
numPrintDigits = numFractionDigits;
|
||||
}
|
||||
|
||||
// add the decimal point
|
||||
if (maxPrintLen > 1)
|
||||
{
|
||||
pOutBuffer[1] = fractionPoint;
|
||||
numPrintDigits += 1;
|
||||
}
|
||||
|
||||
// add the initial zero
|
||||
if (maxPrintLen > 0)
|
||||
{
|
||||
pOutBuffer[0] = '0';
|
||||
numPrintDigits += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// add trailing zeros up to precision length
|
||||
if (precision > (int32_t)numFractionDigits && numPrintDigits < maxPrintLen)
|
||||
{
|
||||
// add a decimal point if this is the first fractional digit we are printing
|
||||
if (numFractionDigits == 0)
|
||||
{
|
||||
pOutBuffer[numPrintDigits++] = fractionPoint;
|
||||
}
|
||||
|
||||
// compute the number of trailing zeros needed
|
||||
uint32_t totalDigits = numPrintDigits + (precision - numFractionDigits);
|
||||
if (totalDigits > maxPrintLen)
|
||||
totalDigits = maxPrintLen;
|
||||
|
||||
for (; numPrintDigits < totalDigits; ++numPrintDigits)
|
||||
pOutBuffer[numPrintDigits] = '0';
|
||||
}
|
||||
|
||||
pOutBuffer[numPrintDigits] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t numPrintDigits;
|
||||
numPrintDigits = Dragon4(mantissa,
|
||||
exponent,
|
||||
mantissaHighBitIdx,
|
||||
hasUnequalMargins,
|
||||
CutoffMode_TotalLength,
|
||||
precision + 1,
|
||||
pOutBuffer,
|
||||
bufferSize,
|
||||
&printExponent);
|
||||
|
||||
char *pCurOut = pOutBuffer;
|
||||
pCurOut += 1;
|
||||
|
||||
// insert the decimal point prior to the fractional number
|
||||
uint32_t numFractionDigits = numPrintDigits - 1;
|
||||
if (numFractionDigits > 0 && bufferSize > 1)
|
||||
{
|
||||
uint32_t maxFractionDigits = bufferSize - 2;
|
||||
if (numFractionDigits > maxFractionDigits)
|
||||
numFractionDigits = maxFractionDigits;
|
||||
|
||||
MemCopy(pCurOut + 1, pCurOut, numFractionDigits);
|
||||
pCurOut[0] = fractionPoint;
|
||||
pCurOut += (1 + numFractionDigits);
|
||||
}
|
||||
|
||||
pCurOut[0] = '\0';
|
||||
}
|
||||
|
||||
buf->EnsureGrowth(size);
|
||||
buf->Append(out);
|
||||
|
||||
if (fractionPoint != '\0' && buf->Contains(fractionPoint))
|
||||
{
|
||||
while (buf->RemoveTrailing('0'))
|
||||
;
|
||||
buf->RemoveTrailing(fractionPoint);
|
||||
}
|
||||
|
||||
if (printExponent != 0)
|
||||
{
|
||||
buf->Append('e');
|
||||
if (printExponent >= 0)
|
||||
{
|
||||
buf->Append('+');
|
||||
}
|
||||
else
|
||||
{
|
||||
buf->Append('-');
|
||||
printExponent = -printExponent;
|
||||
}
|
||||
int temp;
|
||||
IntegerToBuffer(printExponent, 3, &temp);
|
||||
}
|
||||
|
||||
if (fractionPoint != '\0' && buf->Contains(fractionPoint) && !buf->Contains('e'))
|
||||
{
|
||||
while (buf->RemoveTrailing('0'))
|
||||
;
|
||||
buf->RemoveTrailing(fractionPoint);
|
||||
}
|
||||
|
||||
delete[] out;
|
||||
return buf->GetString();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_NUMERAL_DECIMAL_H
|
||||
#define AMATH_NUMERAL_DECIMAL_H
|
||||
|
||||
#include "ntextp.h"
|
||||
|
||||
class DecimalSystem : public PositionalNumeralSystem
|
||||
{
|
||||
public:
|
||||
DecimalSystem();
|
||||
DecimalSystem(unsigned int digits);
|
||||
DecimalSystem(unsigned int digits, const char fractionPoint);
|
||||
~DecimalSystem();
|
||||
virtual const char *GetText(Number *number);
|
||||
|
||||
private:
|
||||
const char *GetText(double number) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,425 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#include "amath.h"
|
||||
#include "amathc.h"
|
||||
#include "mathr.h"
|
||||
#include "mathi.h"
|
||||
#include "real.h"
|
||||
#include "cplex.h"
|
||||
#include "ntext.h"
|
||||
#include "ntextd.h"
|
||||
#include "charbuf.h"
|
||||
|
||||
PositionalNumeralSystem::PositionalNumeralSystem(
|
||||
unsigned int base,
|
||||
unsigned int digits,
|
||||
const char fractionPoint) : base(base * 1.0), digits(digits)
|
||||
{
|
||||
this->fractionPoint = fractionPoint;
|
||||
}
|
||||
|
||||
PositionalNumeralSystem::~PositionalNumeralSystem()
|
||||
{
|
||||
}
|
||||
|
||||
const char *PositionalNumeralSystem::GetName()
|
||||
{
|
||||
switch (static_cast<int>(base))
|
||||
{
|
||||
case 2:
|
||||
return "binary";
|
||||
case 8:
|
||||
return "octal";
|
||||
case 10:
|
||||
return "decimal";
|
||||
case 16:
|
||||
return "hexadecimal";
|
||||
}
|
||||
|
||||
const char *text = "base ";
|
||||
Number *n = new RealNumber(base);
|
||||
NumeralSystem *ns = new DecimalSystem(2);
|
||||
const char *numtext = ns->GetText(n);
|
||||
|
||||
buf->EnsureSize(StrLen(text) + StrLen(numtext) + 1);
|
||||
buf->Empty();
|
||||
buf->Append(text);
|
||||
buf->Append(numtext);
|
||||
|
||||
delete ns;
|
||||
delete n;
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
const char *PositionalNumeralSystem::GetPrefix()
|
||||
{
|
||||
// TODO: Consider using prefix with numral systems != base 10
|
||||
return EMPTYSTRING;
|
||||
}
|
||||
|
||||
unsigned int PositionalNumeralSystem::GetDigits()
|
||||
{
|
||||
return digits;
|
||||
}
|
||||
|
||||
void PositionalNumeralSystem::SetDigits(unsigned int digits)
|
||||
{
|
||||
this->digits = digits;
|
||||
}
|
||||
|
||||
const char PositionalNumeralSystem::GetFractionPoint()
|
||||
{
|
||||
return static_cast<const char>(this->fractionPoint);
|
||||
}
|
||||
|
||||
void PositionalNumeralSystem::SetFractionPoint(const char fractionPoint)
|
||||
{
|
||||
this->fractionPoint = fractionPoint;
|
||||
}
|
||||
|
||||
const char *PositionalNumeralSystem::GetSpecialCase(Number *number)
|
||||
{
|
||||
if (number->IsNaN())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("NaN");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsNotImplemented())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("NotImplemented");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsInfinite() && number->IsNegative())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("-Inf");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsInfinite() && !number->IsNegative())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("Inf");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
if (number->IsZero())
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append("0");
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char *PositionalNumeralSystem::GetText(Number *number)
|
||||
{
|
||||
const char *sc = GetSpecialCase(number);
|
||||
if (sc != nullptr)
|
||||
{
|
||||
return sc;
|
||||
}
|
||||
|
||||
if (number->system == nsysreal)
|
||||
{
|
||||
return GetText(number->GetRealValue());
|
||||
}
|
||||
|
||||
complex w = static_cast<ComplexNumber *>(number)->GetComplexValue();
|
||||
double a = creal(w);
|
||||
double b = cimag(w);
|
||||
|
||||
if (a == 0.0 && b == 0.0)
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append('0');
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
CharBuffer *val = new CharBuffer(512);
|
||||
val->Empty();
|
||||
|
||||
if (a != 0.0)
|
||||
{
|
||||
const char *real = GetText(a);
|
||||
val->Append(real);
|
||||
}
|
||||
|
||||
const char *imag = GetText(b);
|
||||
if (a != 0.0 && b > 0.0)
|
||||
{
|
||||
val->Append('+');
|
||||
}
|
||||
|
||||
if (b != 0.0)
|
||||
{
|
||||
val->Append(imag);
|
||||
val->Append('i');
|
||||
}
|
||||
|
||||
buf->Copy(val);
|
||||
delete val;
|
||||
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
const char *PositionalNumeralSystem::GetText(double number) const
|
||||
{
|
||||
if (number == 0.0)
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
buf->Empty();
|
||||
|
||||
double dnumber = number;
|
||||
if (dnumber < 0.0)
|
||||
{
|
||||
buf->Append('-');
|
||||
dnumber = -dnumber;
|
||||
}
|
||||
|
||||
double expbor = log2p(base, dnumber);
|
||||
double expacc = expbor > 0.0 ? 4e-14 : -1e-15;
|
||||
double expborder = trunc(expbor + expacc);
|
||||
|
||||
int exponent = 0;
|
||||
double rounding;
|
||||
|
||||
double bordermax = trunc(9.0 * 10 / base);
|
||||
double bordermin = trunc(-8.0 * 10 / base);
|
||||
|
||||
// Find exponent
|
||||
if (expborder >= bordermax || expborder <= bordermin)
|
||||
{
|
||||
double dexp = trunc(log2p(base, dnumber) + expacc);
|
||||
dnumber = dnumber * pow(base, -dexp);
|
||||
|
||||
// pow is inaccurate on small and large numbers
|
||||
if (dexp > 15 || dexp < -15)
|
||||
{
|
||||
dnumber += 2e-15;
|
||||
}
|
||||
|
||||
// Adjust if below zero
|
||||
if (dnumber < 1.0)
|
||||
{
|
||||
dexp--;
|
||||
dnumber *= base;
|
||||
}
|
||||
|
||||
exponent = static_cast<int>(dexp);
|
||||
rounding = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
double acc = exponent > 0 ? 15 : -15;
|
||||
rounding = pow(base, exponent + acc);
|
||||
}
|
||||
|
||||
int digitout;
|
||||
int intdigits;
|
||||
|
||||
double intvalue = trunc(dnumber + rounding);
|
||||
IntegerToBuffer(intvalue, digits, &intdigits);
|
||||
|
||||
int fragdigits = digits - intdigits + (intvalue < 1.0 ? 1 : 0);
|
||||
if (fragdigits > 0)
|
||||
{
|
||||
buf->Append(fractionPoint);
|
||||
|
||||
double fraction = fabs(round((dnumber - intvalue) * pow(base, fragdigits)));
|
||||
double temp1 = log2p(base, fraction);
|
||||
FloatUnion64 temp2;
|
||||
temp2.floatingPoint = temp1;
|
||||
bool fin = !temp2.IsInf();
|
||||
int actualdigits = static_cast<int>(trunc(temp1 + 3e-15));
|
||||
int padding = fragdigits - (fin == 1 ? actualdigits : 0) - 1;
|
||||
|
||||
// Pad zeros if needed
|
||||
while (padding-- > 0)
|
||||
{
|
||||
buf->Append('0');
|
||||
}
|
||||
|
||||
intvalue = static_cast<int64_t>(trunc(fraction * base) / base);
|
||||
IntegerToBuffer(intvalue, fragdigits, &digitout);
|
||||
|
||||
// Remove trailing zeros
|
||||
// ReSharper disable once CppPossiblyErroneousEmptyStatements
|
||||
while (buf->RemoveTrailing('0'))
|
||||
;
|
||||
|
||||
buf->RemoveTrailing(fractionPoint);
|
||||
}
|
||||
|
||||
// Add exponent
|
||||
if (exponent != 0)
|
||||
{
|
||||
buf->Append('e');
|
||||
buf->Append(exponent > 0 ? '+' : '-');
|
||||
IntegerToBuffer(abs(exponent), 3, &digitout);
|
||||
}
|
||||
|
||||
// Make sure no rounding error is returned
|
||||
if (buf->Is("-0"))
|
||||
{
|
||||
buf->Empty();
|
||||
buf->Append('0');
|
||||
}
|
||||
|
||||
return buf->GetString();
|
||||
}
|
||||
|
||||
void PositionalNumeralSystem::IntegerToBuffer(double value, unsigned int digits, int *outdigits) const
|
||||
{
|
||||
static const char *alphaNumerics = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
unsigned int count = 0;
|
||||
char *chars = new char[128];
|
||||
char *start = chars;
|
||||
|
||||
do
|
||||
{
|
||||
count++;
|
||||
unsigned int intremainder = static_cast<unsigned int>(trunc(fmod(value, base)));
|
||||
*chars++ = alphaNumerics[intremainder];
|
||||
value /= base;
|
||||
} while (value >= 1.0);
|
||||
|
||||
unsigned int n = count;
|
||||
unsigned int q = digits;
|
||||
chars--;
|
||||
|
||||
while (n-- != 0 && q-- != 0)
|
||||
{
|
||||
buf->Append(*chars--);
|
||||
}
|
||||
|
||||
n++;
|
||||
while (n-- != 0)
|
||||
{
|
||||
buf->Append('0');
|
||||
}
|
||||
|
||||
*outdigits = count;
|
||||
delete[] start;
|
||||
}
|
||||
|
||||
Number *PositionalNumeralSystem::Parse(const char *text, unsigned int *length, char **end)
|
||||
{
|
||||
unsigned int intbase = static_cast<unsigned int>(base);
|
||||
char maxNumeric = (intbase > 10 ? 10 : intbase) + '0' - 1;
|
||||
char maxAlpha = intbase > 10 ? intbase + 'A' - 11 : 0;
|
||||
|
||||
unsigned int pos = 0;
|
||||
double integer = 0;
|
||||
double addition;
|
||||
|
||||
while (*text != '\0' && ((*text >= '0' && *text <= maxNumeric) || (maxAlpha != 0 && *text >= 'A' && *text <= maxAlpha)))
|
||||
{
|
||||
addition = ((*text >= '0' && *text <= maxNumeric) ? (*text - '0') : (*text - 'A' + 10)) * 1.0;
|
||||
integer = integer * base + addition;
|
||||
text++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
// Digits not found
|
||||
if (pos == 0)
|
||||
{
|
||||
*length = 0;
|
||||
*end = const_cast<char*>(text);
|
||||
return new RealNumber();
|
||||
}
|
||||
|
||||
double fraction = 0.0;
|
||||
double divisor = 1.0;
|
||||
if (*text == fractionPoint && fractionPoint != '\0')
|
||||
{
|
||||
text++;
|
||||
pos++;
|
||||
|
||||
while (*text != '\0' && ((*text >= '0' && *text <= maxNumeric) || (maxAlpha != '\0' && *text >= 'A' && *text <= maxAlpha)))
|
||||
{
|
||||
addition = ((*text >= '0' && *text <= maxNumeric) ? (*text - '0') : (*text - 'A' + 10));
|
||||
fraction = fraction * base + addition;
|
||||
divisor *= base;
|
||||
text++;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
|
||||
double exp = 0.0;
|
||||
if (*text == 'e' || *text == 'E')
|
||||
{
|
||||
text++;
|
||||
pos++;
|
||||
|
||||
double sign = *text == '+' ? 1.0 : *text == '-' ? -1.0 : 0.0;
|
||||
|
||||
if (sign != 0.0)
|
||||
{
|
||||
text++;
|
||||
pos++;
|
||||
|
||||
while (*text != '\0' && ((*text >= '0' && *text <= maxNumeric) || (maxAlpha != 0 && *text >= 'A' && *text <= maxAlpha)))
|
||||
{
|
||||
addition = ((*text >= '0' && *text <= maxNumeric) ? (*text - '0') : (*text - 'A' + 10)) * 1.0;
|
||||
exp = exp * base + addition;
|
||||
text++;
|
||||
pos++;
|
||||
}
|
||||
|
||||
exp *= sign;
|
||||
}
|
||||
else
|
||||
{
|
||||
text--;
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
|
||||
*length = pos;
|
||||
*end = const_cast<char*>(text);
|
||||
|
||||
double dnumber = (integer + (fraction / divisor));
|
||||
|
||||
if (exp != 0.0)
|
||||
{
|
||||
// pow seems a bit off
|
||||
dnumber *= pow(base, exp + 4e-15);
|
||||
}
|
||||
|
||||
return new RealNumber(dnumber);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_NUMERAL_POSITIONAL_H
|
||||
#define AMATH_NUMERAL_POSITIONAL_H
|
||||
|
||||
#include "ntext.h"
|
||||
|
||||
/**
|
||||
* @brief Base class for all numeral systems with a positional notation
|
||||
* @details
|
||||
* More info on positional notation is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Positional_notation
|
||||
*/
|
||||
class PositionalNumeralSystem : public NumeralSystem
|
||||
{
|
||||
public:
|
||||
PositionalNumeralSystem(unsigned int base, unsigned int digits, const char fractionPoint);
|
||||
~PositionalNumeralSystem();
|
||||
|
||||
virtual const char* GetName();
|
||||
virtual const char* GetPrefix();
|
||||
virtual unsigned int GetDigits();
|
||||
virtual void SetDigits(unsigned int digits);
|
||||
virtual const char GetFractionPoint();
|
||||
virtual void SetFractionPoint(const char fractionPoint);
|
||||
virtual const char* GetText(Number* number);
|
||||
virtual Number* Parse(const char* text, unsigned int* length, char** end);
|
||||
|
||||
protected:
|
||||
const char* GetSpecialCase(Number *number);
|
||||
void IntegerToBuffer(double value, unsigned int digits, int* outdigits) const;
|
||||
|
||||
double base;
|
||||
unsigned int digits;
|
||||
char fractionPoint;
|
||||
|
||||
private:
|
||||
const char* GetText(double number) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
+24
-10
@@ -36,14 +36,27 @@
|
||||
|
||||
/**
|
||||
* @file numb.h
|
||||
* @brief Class base handling of numbers.
|
||||
*
|
||||
* @brief Class base handling of numbers
|
||||
*/
|
||||
|
||||
#include "amath.h"
|
||||
|
||||
union FloatUnion64 {
|
||||
bool IsNegative() const { return (integer >> 63) != 0; }
|
||||
bool IsZero() const { return integer == 0; }
|
||||
bool IsInf() const { return GetExponent() == 0x7FF && GetMantissa() == 0; }
|
||||
bool IsNaN() const { return GetExponent() == 0x7FF && GetMantissa() != 0; }
|
||||
bool IsMaxPositive() const { return integer == 0x7EFFFFFFFFFFFFFFull; }
|
||||
bool IsMaxNegative() const { return integer == 0x7FFFFFFFFFFFFFFFull; }
|
||||
int32_t GetExponent() const { return (integer >> 52) & 0x7FF; }
|
||||
uint64_t GetMantissa() const { return integer & 0xFFFFFFFFFFFFFull; }
|
||||
double floatingPoint;
|
||||
uint64_t integer;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
nsysnatural,
|
||||
nsysinteger,
|
||||
nsysrational,
|
||||
nsysreal,
|
||||
nsyscomplex,
|
||||
@@ -68,10 +81,10 @@ public:
|
||||
virtual bool PureComplexValue() = 0;
|
||||
virtual int GetPrecedence() = 0;
|
||||
virtual int GetDefaultPrecedence() = 0;
|
||||
virtual bool IsNegative() = 0;
|
||||
virtual bool IsZero() = 0;
|
||||
virtual bool IsNaN() = 0;
|
||||
virtual bool IsTooSmall() = 0;
|
||||
virtual bool IsTooLarge() = 0;
|
||||
virtual bool IsInfinite() = 0;
|
||||
virtual bool IsNotImplemented() = 0;
|
||||
|
||||
virtual Number* Unary() = 0;
|
||||
@@ -102,6 +115,9 @@ public:
|
||||
virtual Number* Cosecant() = 0;
|
||||
virtual Number* Secant() = 0;
|
||||
virtual Number* Cotangent() = 0;
|
||||
virtual Number* Chord() = 0;
|
||||
virtual Number* ExSecant() = 0;
|
||||
virtual Number* ExCosecant() = 0;
|
||||
|
||||
virtual Number* ArcSine() = 0;
|
||||
virtual Number* ArcCosine() = 0;
|
||||
@@ -109,6 +125,9 @@ public:
|
||||
virtual Number* ArcCosecant() = 0;
|
||||
virtual Number* ArcSecant() = 0;
|
||||
virtual Number* ArcCotangent() = 0;
|
||||
virtual Number* ArcChord() = 0;
|
||||
virtual Number* ArcExSecant() = 0;
|
||||
virtual Number* ArcExCosecant() = 0;
|
||||
|
||||
virtual Number* HypSine() = 0;
|
||||
virtual Number* HypCosine() = 0;
|
||||
@@ -142,11 +161,6 @@ public:
|
||||
virtual Number* ArcHaCoVerSine() = 0;
|
||||
virtual Number* ArcHaCoVerCosine() = 0;
|
||||
|
||||
virtual Number* ExSecant() = 0;
|
||||
virtual Number* ExCosecant() = 0;
|
||||
virtual Number* ArcExSecant() = 0;
|
||||
virtual Number* ArcExCosecant() = 0;
|
||||
|
||||
friend class PositionalNumeralSystem;
|
||||
friend class DecimalSystem;
|
||||
friend struct IntegerNumber;
|
||||
|
||||
+464
-432
File diff suppressed because it is too large
Load Diff
+11
-12
@@ -32,17 +32,15 @@
|
||||
|
||||
/**
|
||||
* @file real.h
|
||||
* @brief Class based handling of real numbers.
|
||||
*
|
||||
* @brief Class based handling of real numbers
|
||||
*/
|
||||
|
||||
#include "numb.h"
|
||||
|
||||
/**
|
||||
* @brief Represent a real number with 15 significant digits.
|
||||
* @brief Represent a real number with 15 significant digits
|
||||
* @details
|
||||
* Calculations are done using 64 bit IEEE 754 arithmetics.
|
||||
*
|
||||
*/
|
||||
struct RealNumber : public Number
|
||||
{
|
||||
@@ -61,10 +59,10 @@ public:
|
||||
bool PureComplexValue();
|
||||
int GetPrecedence();
|
||||
int GetDefaultPrecedence();
|
||||
bool IsNegative();
|
||||
bool IsZero();
|
||||
bool IsNaN();
|
||||
bool IsTooSmall();
|
||||
bool IsTooLarge();
|
||||
bool IsInfinite();
|
||||
bool IsNotImplemented();
|
||||
|
||||
Number* Unary();
|
||||
@@ -95,12 +93,18 @@ public:
|
||||
Number* Cosecant();
|
||||
Number* Secant();
|
||||
Number* Cotangent();
|
||||
Number* Chord();
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcSine();
|
||||
Number* ArcCosine();
|
||||
Number* ArcTangent();
|
||||
Number* ArcCosecant();
|
||||
Number* ArcSecant();
|
||||
Number* ArcCotangent();
|
||||
Number* ArcSecant();
|
||||
Number* ArcChord();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
|
||||
Number* HypSine();
|
||||
Number* HypCosine();
|
||||
@@ -133,11 +137,6 @@ public:
|
||||
Number* ArcHaCoVerSine();
|
||||
Number* ArcHaCoVerCosine();
|
||||
|
||||
Number* ExSecant();
|
||||
Number* ExCosecant();
|
||||
Number* ArcExSecant();
|
||||
Number* ArcExCosecant();
|
||||
|
||||
friend struct ComplexNumber;
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,19 +30,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_LOCALIZE_HELP_H
|
||||
#define AMATH_LOCALIZE_HELP_H
|
||||
#ifndef AMATH_LOCALE_HELP_H
|
||||
#define AMATH_LOCALE_HELP_H
|
||||
|
||||
/**
|
||||
* @file localize/help.h
|
||||
* @brief Help texts for statement.
|
||||
*
|
||||
* @file loc/help.h
|
||||
* @brief Help texts for statement
|
||||
*/
|
||||
|
||||
#include "amath.h"
|
||||
#include "amathc.h"
|
||||
#include "amatht.h"
|
||||
#include "localize/lex.h"
|
||||
#include "main/symbol.h"
|
||||
|
||||
#define symzero Symbol(0)
|
||||
|
||||
@@ -54,12 +53,12 @@ struct helptextdef
|
||||
};
|
||||
|
||||
static const helptextdef helptexts[] = {
|
||||
{ 0, symzero, "Enter command or expression to evaluate.#NEWLINE##SYNTAXHIGHLIGHT#Example: 2+3-cos(3)#NORMALTEXT##NEWLINE# #NEWLINE#More help is available for designated topics.#NEWLINE#-------------------------------------------------#NEWLINE#functions Base functions.#NEWLINE#trigon Trigonometric functions.#NEWLINE#hyper Hyperbolic functions.#NEWLINE#early Early trigonometric functions.#NEWLINE#complex Syntax for complex numbers.#NEWLINE#statements Available statements.#NEWLINE#operators Supported operators.#NEWLINE#-------------------------------------------------#NEWLINE##SYNTAXHIGHLIGHT#Example: help trigon#NEWLINE#" },
|
||||
{ 1, symoperator, "-------------------------------------------------#NEWLINE# + Mathematical addition.#NEWLINE# - Mathematical subtraction.#NEWLINE# * Mathematical multiplication.#NEWLINE# / Mathematical division.#NEWLINE# ^ Mathematical exponentiation.#NEWLINE# = Assignment of variable values.#NEWLINE# | Absolute value of number. #NEWLINE#-------------------------------------------------#NEWLINE#" },
|
||||
{ 2, symfunction, "-------------------------------------------------#NEWLINE#abs Absolute value of number.#NEWLINE#sgn Mathematical signum function.#NEWLINE#round Round to nearest integer number.#NEWLINE#trunc Discard fraction part of number.#NEWLINE#floor Mathematical floor function.#NEWLINE#ceil Mathematical ceiling function.#NEWLINE#sqrt Square root function (exp 1/2).#NEWLINE#cbrt Cube root function (exp 1/3).#NEWLINE#lb Binary logarithm function (base 2).#NEWLINE#ln Natural logarithm function (base e).#NEWLINE#lg Common logarithm function (base 10).#NEWLINE#-------------------------------------------------#NEWLINE##SYNTAXHIGHLIGHT#Example: round(1.55)#NORMALTEXT##NEWLINE#" },
|
||||
{ 3, symtrigon, "-------------------------------------------------#NEWLINE#sin Trigonometric sine function.#NEWLINE#cos Trigonometric cosine function.#NEWLINE#tan Trigonometric tangent function.#NEWLINE#cot Trigonometric cotangent function.#NEWLINE#sec Trigonometric secant function.#NEWLINE#csc Trigonometric cosecant function.#NEWLINE#exsec Trigonometric exsecant function.#NEWLINE#excsc Trigonometric excosecant function.#NEWLINE#asin Inverse trigonometric sine function.#NEWLINE#acos Inverse trigonometric cosine function.#NEWLINE#atan Inverse trigonometric tangent function.#NEWLINE#acot Inverse trigonometric cotangent function.#NEWLINE#asec Inverse trigonometric secant function.#NEWLINE#acsc Inverse trigonometric cosecant function.#NEWLINE#exsec Inverse trigonometric exsecant function.#NEWLINE#excsc Inverse trigonometric excosecant function.#NEWLINE#-------------------------------------------------#NEWLINE#Inverse functions can be prefixed with ar or arc #NEWLINE#instead of a.#NEWLINE#" },
|
||||
{ 4, symhyper, "-------------------------------------------------#NEWLINE#sinh Hyperbolic sine function.#NEWLINE#cosh Hyperbolic cosine function.#NEWLINE#tanh Hyperbolic tangent function.#NEWLINE#coth Hyperbolic cotangent function.#NEWLINE#sech Hyperbolic secant function.#NEWLINE#csch Hyperbolic cosecant function. #NEWLINE#asinh Inverse hyperbolic sine function.#NEWLINE#acosh Inverse hyperbolic cosine function.#NEWLINE#atanh Inverse hyperbolic tangent function.#NEWLINE#acoth Inverse hyperbolic cotangent function.#NEWLINE#asech Inverse hyperbolic secant function.#NEWLINE#acsch Inverse hyperbolic cosecant function.#NEWLINE#-------------------------------------------------#NEWLINE#Inverse functions can be prefixed with ar or arc #NEWLINE#instead of a.#NEWLINE#" },
|
||||
{ 5, symearly, "-------------------------------------------------#NEWLINE#ver Versed sine function.#NEWLINE#vcs Versed cosine function.#NEWLINE#cvs Coversed sine function.#NEWLINE#cvc Coversed cosine function.#NEWLINE#hv Haversed sine function.#NEWLINE#hvc Haversed cosine function.#NEWLINE#hcv Hacoversed sine function.#NEWLINE#hcc Hacoversed cosine function.#NEWLINE#aver Inverse versed sine function.#NEWLINE#avcs Inverse versed cosine function.#NEWLINE#acvs Inverse coversed sine function.#NEWLINE#acvc Inverse coversed cosine function.#NEWLINE#ahv Inverse haversed sine function.#NEWLINE#ahvc Inverse haversed cosine function.#NEWLINE#ahcv Inverse hacoversed sine function.#NEWLINE#ahcc Inverse hacoversed cosine function.#NEWLINE#-------------------------------------------------#NEWLINE#Inverse functions can be prefixed with ar or arc #NEWLINE#instead of a.#NEWLINE#" },
|
||||
{ 0, symzero, "Enter command or expression to evaluate.#NEWLINE##SYNTAXHIGHLIGHT#Example: 2+3-cos(3)#NORMALTEXT##NEWLINE# #NEWLINE#More help is available for designated topics.#NEWLINE#----------------------------------------------------#NEWLINE#functions Base functions#NEWLINE#trigon Trigonometric functions#NEWLINE#hyper Hyperbolic functions#NEWLINE#early Early trigonometric functions#NEWLINE#complex Syntax for complex numbers#NEWLINE#statements Available statements#NEWLINE#operators Supported operators#NEWLINE#----------------------------------------------------#NEWLINE##SYNTAXHIGHLIGHT#Example: help trigon#NEWLINE#" },
|
||||
{ 1, symoperator, "----------------------------------------------------#NEWLINE# + Mathematical addition#NEWLINE# - Mathematical subtraction#NEWLINE# * Mathematical multiplication#NEWLINE# / Mathematical division#NEWLINE# ^ Mathematical exponentiation#NEWLINE# = Assignment of variable values#NEWLINE# | Absolute value of number#NEWLINE#----------------------------------------------------#NEWLINE#" },
|
||||
{ 2, symfunction, "----------------------------------------------------#NEWLINE#abs Absolute value of number#NEWLINE#sgn Mathematical signum function#NEWLINE#round Round to nearest integer number#NEWLINE#trunc Discard fraction part of number#NEWLINE#floor Mathematical floor function#NEWLINE#ceil Mathematical ceiling function#NEWLINE#sqrt Square root function (exp 1/2)#NEWLINE#cbrt Cube root function (exp 1/3)#NEWLINE#lb Binary logarithm function (base 2)#NEWLINE#ln Natural logarithm function (base e)#NEWLINE#lg Common logarithm function (base 10)#NEWLINE#----------------------------------------------------#NEWLINE##SYNTAXHIGHLIGHT#Example: round(1.55)#NORMALTEXT##NEWLINE#" },
|
||||
{ 3, symtrigon, "----------------------------------------------------#NEWLINE#sin Trigonometric sine function#NEWLINE#cos Trigonometric cosine function#NEWLINE#tan Trigonometric tangent function#NEWLINE#cot Trigonometric cotangent function#NEWLINE#sec Trigonometric secant function#NEWLINE#csc Trigonometric cosecant function#NEWLINE#crd Trigonometric chord function#NEWLINE#exsec Trigonometric exsecant function#NEWLINE#excsc Trigonometric excosecant function#NEWLINE#asin Inverse trigonometric sine function#NEWLINE#acos Inverse trigonometric cosine function#NEWLINE#atan Inverse trigonometric tangent function#NEWLINE#acot Inverse trigonometric cotangent function#NEWLINE#asec Inverse trigonometric secant function#NEWLINE#acsc Inverse trigonometric cosecant function#NEWLINE#acrd Inverse trigonometric chord function#NEWLINE#aexsec Inverse trigonometric exsecant function#NEWLINE#aexcsc Inverse trigonometric excosecant function#NEWLINE#----------------------------------------------------#NEWLINE#Inverse functions can be prefixed with ar or arc#NEWLINE#instead of a.#NEWLINE#" },
|
||||
{ 4, symhyper, "----------------------------------------------------#NEWLINE#sinh Hyperbolic sine function#NEWLINE#cosh Hyperbolic cosine function#NEWLINE#tanh Hyperbolic tangent function#NEWLINE#coth Hyperbolic cotangent function#NEWLINE#sech Hyperbolic secant function#NEWLINE#csch Hyperbolic cosecant function #NEWLINE#asinh Inverse hyperbolic sine function#NEWLINE#acosh Inverse hyperbolic cosine function#NEWLINE#atanh Inverse hyperbolic tangent function#NEWLINE#acoth Inverse hyperbolic cotangent function#NEWLINE#asech Inverse hyperbolic secant function#NEWLINE#acsch Inverse hyperbolic cosecant function#NEWLINE#----------------------------------------------------#NEWLINE#Inverse functions can be prefixed with ar or arc #NEWLINE#instead of a.#NEWLINE#" },
|
||||
{ 5, symearly, "----------------------------------------------------#NEWLINE#ver Versed sine function#NEWLINE#vcs Versed cosine function#NEWLINE#cvs Coversed sine function#NEWLINE#cvc Coversed cosine function#NEWLINE#hv Haversed sine function#NEWLINE#hvc Haversed cosine function#NEWLINE#hcv Hacoversed sine function#NEWLINE#hcc Hacoversed cosine function#NEWLINE#aver Inverse versed sine function#NEWLINE#avcs Inverse versed cosine function#NEWLINE#acvs Inverse coversed sine function#NEWLINE#acvc Inverse coversed cosine function#NEWLINE#ahv Inverse haversed sine function#NEWLINE#ahvc Inverse haversed cosine function#NEWLINE#ahcv Inverse hacoversed sine function#NEWLINE#ahcc Inverse hacoversed cosine function#NEWLINE#----------------------------------------------------#NEWLINE#Inverse functions can be prefixed with ar or arc #NEWLINE#instead of a.#NEWLINE#" },
|
||||
{ 6, symcomplex, "Expressions with complex numbers are written using an i to denote#NEWLINE#the imaginary value. Complex numbers can seamlessly be mixed with#NEWLINE#real numbers.#NEWLINE##SYNTAXHIGHLIGHT#Syntax: 2+3i#NEWLINE#Example: 2+3.2i*cos(-1i)+5/7#NEWLINE#" },
|
||||
{ 7, symclear, "The clear statement erases all text in the console window.#NEWLINE##SYNTAXHIGHLIGHT#Syntax: clear#NEWLINE#" },
|
||||
{ 8, symdef, "The def statement is used to define functions. When defining a function#NEWLINE#it is possible to omit the def keyword. Defined functions can be shown#NEWLINE#using the functions statement.#NEWLINE##SYNTAXHIGHLIGHT#Syntax: def f(x)=2*x+3#NEWLINE#Optional syntax: f(x)=2*x+3#NEWLINE#" },
|
||||
@@ -30,13 +30,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_LOCALIZE_IDENT_H
|
||||
#define AMATH_LOCALIZE_IDENT_H
|
||||
#ifndef AMATH_LOCALE_IDENT_H
|
||||
#define AMATH_LOCALE_IDENT_H
|
||||
|
||||
/**
|
||||
* @file localize/ident.h
|
||||
* @brief Help texts for built-in functions.
|
||||
*
|
||||
* @file loc/ident.h
|
||||
* @brief Help texts for built-in functions
|
||||
*/
|
||||
|
||||
#include "amath.h"
|
||||
@@ -30,22 +30,20 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_LOCALIZE_KEYWORD_H
|
||||
#define AMATH_LOCALIZE_KEYWORD_H
|
||||
#ifndef AMATH_LOCALE_KEYWORD_H
|
||||
#define AMATH_LOCALE_KEYWORD_H
|
||||
|
||||
/**
|
||||
* @file localize/kword.h
|
||||
* @brief Keywords used by lexer.
|
||||
*
|
||||
* @file loc/kword.h
|
||||
* @brief Keywords used by lexer
|
||||
*/
|
||||
|
||||
#include "amath.h"
|
||||
#include "amathc.h"
|
||||
#include "localize/lex.h"
|
||||
#include "main/symbol.h"
|
||||
|
||||
/**
|
||||
* @brief Character representation of keyword tied with its symbol.
|
||||
*
|
||||
* @brief Character representation of keyword tied with its symbol
|
||||
*/
|
||||
struct keyworddef
|
||||
{
|
||||
@@ -30,13 +30,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_LOCALIZE_TEXT_H
|
||||
#define AMATH_LOCALIZE_TEXT_H
|
||||
#ifndef AMATH_LOCALE_TEXT_H
|
||||
#define AMATH_LOCALE_TEXT_H
|
||||
|
||||
/**
|
||||
* @file localize/text.h
|
||||
* @brief Static texts in amath.
|
||||
*
|
||||
* @file loc/text.h
|
||||
* @brief Static texts in amath
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
@@ -102,27 +101,27 @@
|
||||
|
||||
static const textdef textdefs[] = {
|
||||
{ 0, "#NORMALTEXT##BOLD##STARTMSG##NEWLINE##NORMALTEXT##COLOR02#Type help to show info.#NEWLINE#" }, /* INTROMSG */
|
||||
{ 1, "---------------------------------------------------------#NEWLINE#" }, /* STATEMENTLINE */
|
||||
{ 2, "clear Clear console window.#NEWLINE#" }, /* STATEMENTCLEAR */
|
||||
{ 3, "def Define function.#NEWLINE#" }, /* STATEMENTDEF */
|
||||
{ 4, "delete Delete variable or function.#NEWLINE#" }, /* STATEMENTDELETE */
|
||||
{ 5, "digits Set number of significant digits.#NEWLINE#" }, /* STATEMENTDIGITS */
|
||||
{ 6, "eval Evaluate arithmetic expression.#NEWLINE#" }, /* STATEMENTEVAL */
|
||||
{ 7, "execute Execute statements in a file.#NEWLINE#" }, /* STATEMENTEXECUTE */
|
||||
{ 8, "functions Show list of user defined functions.#NEWLINE#" }, /* STATEMENTFUNCS */
|
||||
{ 9, "input Change numeral input system.#NEWLINE#" }, /* STATEMENTINPUT */
|
||||
{ 10, "help Show basic help text.#NEWLINE#" }, /* STATEMENTHELP */
|
||||
{ 11, "output Change numeral output system.#NEWLINE#" }, /* STATEMENTOUTPUT */
|
||||
{ 12, "list Show content of a directory.#NEWLINE#" }, /* STATEMENTLIST */
|
||||
{ 13, "show Show content of a file.#NEWLINE#" }, /* STATEMENTSHOW */
|
||||
{ 14, "load Load variable and functions from file.#NEWLINE#" }, /* STATEMENTLOAD */
|
||||
{ 15, "save Save variable and functions to file.#NEWLINE#" }, /* STATEMENTSAVE */
|
||||
{ 16, "variables Show list of variables.#NEWLINE#" }, /* STATEMENTVARS */
|
||||
{ 17, "version Show version string.#NEWLINE#" }, /* STATEMENTVERSION */
|
||||
{ 18, "memory Show internal memory usage.#NEWLINE#" }, /* STATEMENTMEMORY */
|
||||
{ 19, "exit Exit program.#NEWLINE#" }, /* STATEMENTEXIT */
|
||||
{ 1, "------------------------------------------------------------#NEWLINE#" }, /* STATEMENTLINE */
|
||||
{ 2, "clear Clear console window#NEWLINE#" }, /* STATEMENTCLEAR */
|
||||
{ 3, "def Define function#NEWLINE#" }, /* STATEMENTDEF */
|
||||
{ 4, "delete Delete variable or function#NEWLINE#" }, /* STATEMENTDELETE */
|
||||
{ 5, "digits Set number of significant digits#NEWLINE#" }, /* STATEMENTDIGITS */
|
||||
{ 6, "eval Evaluate arithmetic expression#NEWLINE#" }, /* STATEMENTEVAL */
|
||||
{ 7, "execute Execute statements in a file#NEWLINE#" }, /* STATEMENTEXECUTE */
|
||||
{ 8, "functions Show list of user defined functions#NEWLINE#" }, /* STATEMENTFUNCS */
|
||||
{ 9, "input Change numeral input system#NEWLINE#" }, /* STATEMENTINPUT */
|
||||
{ 10, "help Show basic help text#NEWLINE#" }, /* STATEMENTHELP */
|
||||
{ 11, "output Change numeral output system#NEWLINE#" }, /* STATEMENTOUTPUT */
|
||||
{ 12, "list Show content of a directory#NEWLINE#" }, /* STATEMENTLIST */
|
||||
{ 13, "show Show content of a file#NEWLINE#" }, /* STATEMENTSHOW */
|
||||
{ 14, "load Load variable and functions from file#NEWLINE#" }, /* STATEMENTLOAD */
|
||||
{ 15, "save Save variable and functions to file#NEWLINE#" }, /* STATEMENTSAVE */
|
||||
{ 16, "variables Show list of variables#NEWLINE#" }, /* STATEMENTVARS */
|
||||
{ 17, "version Show version string#NEWLINE#" }, /* STATEMENTVERSION */
|
||||
{ 18, "memory Show internal memory usage#NEWLINE#" }, /* STATEMENTMEMORY */
|
||||
{ 19, "exit Exit program#NEWLINE#" }, /* STATEMENTEXIT */
|
||||
{ 20, "The def and eval statements are optional. Functions and#NEWLINE#variables statements can be shorten to funcs and vars.#NEWLINE#" }, /* STATEMENTFOOTER */
|
||||
{ 21, "Type Name#NEWLINE#-----------------------------------------------#NEWLINE#" }, /* TXTLISTDIRHEADER */
|
||||
{ 21, "Type Name#NEWLINE#--------------------------------------------------#NEWLINE#" }, /* TXTLISTDIRHEADER */
|
||||
{ 22, "[file]" }, /* TXTLISTDIRTFILE */
|
||||
{ 23, "[dir]" }, /* TXTLISTDIRTDIR */
|
||||
{ 24, "[unknown]" }, /* TXTLISTDIRTUNKNOWN */
|
||||
@@ -73,6 +73,12 @@ void __CRTDECL operator delete (void* ptr) throw() { FreeMemSafe(ptr); }
|
||||
void __CRTDECL operator delete[] (void* ptr) throw() { FreeMemSafe(ptr); }
|
||||
#endif
|
||||
|
||||
#if defined(WITHTEST)
|
||||
#include <stdio.h>
|
||||
void WriteOut(const char *string) { printf("%s", string); }
|
||||
void WriteOutInt(int value) { printf("%i", value); }
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#if defined(WITHTEST)
|
||||
|
||||
+42
-30
@@ -50,13 +50,13 @@
|
||||
\subsection usage Usage
|
||||
amath supply 50 \ref command_page combined with 7 arithmetic operators:
|
||||
\verbatim
|
||||
+ Mathematical addition.
|
||||
- Mathematical subtraction.
|
||||
* Mathematical multiplication.
|
||||
/ Mathematical division.
|
||||
^ Mathematical exponentiation.
|
||||
= Assignment of variable values.
|
||||
| Absolute value of number.
|
||||
+ Mathematical addition
|
||||
- Mathematical subtraction
|
||||
* Mathematical multiplication
|
||||
/ Mathematical division
|
||||
^ Mathematical exponentiation
|
||||
= Assignment of variable values
|
||||
| Absolute value of number
|
||||
\endverbatim
|
||||
|
||||
Do a calculation in shell (CLI mode):
|
||||
@@ -73,18 +73,23 @@
|
||||
|
||||
\subsection license License
|
||||
amath is open source. The main repository is located at gitlab:<BR>
|
||||
https://gitlab.com/rnger/amath
|
||||
https://gitlab.com/rnger/amath <BR>
|
||||
<BR>
|
||||
Github has a mirror:<BR>
|
||||
https://github.com/rainlance/amath
|
||||
|
||||
\subsection download Download
|
||||
Windows: https://gitlab.com/rnger/amath-bin/tree/master/Windows <BR>
|
||||
Windows: http://amath.innolan.net/amath-1.8.0.zip <BR>
|
||||
<BR>
|
||||
FreeBSD: https://www.freshports.org/math/amath/ <BR>
|
||||
<BR>
|
||||
NetBSD: http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/math/amath/README.html <BR>
|
||||
<BR>
|
||||
Haiku: https://github.com/haikuports <BR>
|
||||
<BR>
|
||||
Included in the Icaros Desktop environment: http://vmwaros.blogspot.com/ <BR>
|
||||
<BR>
|
||||
Other packages: https://gitlab.com/rnger/amath-bin/tree/master
|
||||
Other packages: https://ranger.innolan.net/rainlance/amath/releases
|
||||
\subsection history History
|
||||
A full \ref release_page is available for amath.
|
||||
|
||||
@@ -134,12 +139,18 @@
|
||||
cot Trigonometric cotangent function
|
||||
sec Trigonometric secant function
|
||||
csc Trigonometric cosecant function
|
||||
crd Trigonometric chord function
|
||||
exsec Trigonometric exsecant function
|
||||
excsc Trigonometric excosecant function
|
||||
arcsin Inverse trigonometric sine function
|
||||
arccos Inverse trigonometric cosine function
|
||||
arctan Inverse trigonometric tangent function
|
||||
arccot Inverse trigonometric cotangent function
|
||||
arcsec Inverse trigonometric secant function
|
||||
arccsc Inverse trigonometric cosecant function
|
||||
arccrd Inverse trigonometric chord function
|
||||
arcexsec Inverse trigonometric exsecant function
|
||||
arcexcsc Inverse trigonometric excosecant function
|
||||
\endverbatim
|
||||
\subsection command_hype Hyperbolic functions
|
||||
\verbatim
|
||||
@@ -219,12 +230,6 @@
|
||||
Copyright (c) 1990, 1993 The Regents of the University of California.
|
||||
All rights reserved.
|
||||
|
||||
This code is derived from software written by Stephen L. Moshier.
|
||||
It is redistributed by the NetBSD Foundation by permission of the author.
|
||||
|
||||
This code is derived from software contributed to Berkeley by
|
||||
Mike Hibler and Chris Torek.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
@@ -253,18 +258,25 @@
|
||||
http://opensource.org/licenses/BSD-2-Clause<BR>
|
||||
https://wikipedia.org/wiki/BSD_licenses<BR>
|
||||
|
||||
|
||||
\page release_page Release history
|
||||
\section release_sec Release history
|
||||
|
||||
\subsection version171 v1.7.1 March 26 2017
|
||||
\subsection version180 1.8.0 April 13 2017
|
||||
- Fixed bugs in numeral systems.
|
||||
- Fixed bugs related to infinity (Inf).
|
||||
- Fixed bugs related to Not a Number (NaN).
|
||||
- Updated and cleanup documentation.
|
||||
- Cleaned up code structure.
|
||||
- OpenLibm support.
|
||||
|
||||
\subsection version171 1.7.1 March 26 2017
|
||||
- Haiku support.
|
||||
- Unified ANSI console.
|
||||
- Code cleanup.
|
||||
|
||||
\subsection version170 v1.7.1 March 12 2017
|
||||
- Introduce scientific notation.
|
||||
- Introduce Not a Number (NaN).
|
||||
\subsection version170 1.7.0 March 12 2017
|
||||
- Introduced scientific notation.
|
||||
- Introduced Not a Number (NaN).
|
||||
- Fixed bugs related to infinity (Inf).
|
||||
- Fixed bugs in log of complex numbers.
|
||||
- Fixed bugs in numeral systems.
|
||||
@@ -272,11 +284,11 @@
|
||||
- Early trigonometric functions.
|
||||
- Static and dynamic libraries.
|
||||
|
||||
\subsection version164 v1.6.4 February 04 2017
|
||||
\subsection version164 1.6.4 February 04 2017
|
||||
- Fixed Windows memory bugs.
|
||||
- Fixed 64 bit memory bugs.
|
||||
|
||||
\subsection version163 v1.6.3 January 30 2017
|
||||
\subsection version163 1.6.3 January 30 2017
|
||||
- Improved error handling.
|
||||
- Fixed error in fraction point parsing.
|
||||
- Fixed typo in help text.
|
||||
@@ -287,20 +299,20 @@
|
||||
- Debian support.
|
||||
- NetBSD support.
|
||||
|
||||
\subsection version162 v1.6.2 January 24 2017
|
||||
\subsection version162 1.6.2 January 24 2017
|
||||
- Fixed bug in memory allocation.
|
||||
- Fixed bug in native keybord input.
|
||||
- Fixed bug in native keyboard input.
|
||||
- Included build options in executables.
|
||||
- ARM support.
|
||||
|
||||
\subsection version161 v1.6.1 January 21 2017
|
||||
\subsection version161 1.6.1 January 21 2017
|
||||
- Fixed language bug in Windows.
|
||||
- Fixed potential memory bugs.
|
||||
- Clang compiler support.
|
||||
- Update copyright texts.
|
||||
- New doxygen documentation.
|
||||
|
||||
\subsection version160 v1.6.0 April 7 2016
|
||||
\subsection version160 1.6.0 April 7 2016
|
||||
- Complete internal restructure of source code.
|
||||
- Fixed several minor bugs in calculation.
|
||||
- Support for Windows & Linux.
|
||||
@@ -352,7 +364,7 @@
|
||||
- Fixed clear console bug on AROS.
|
||||
- Miscellaneous minor bug fixes.
|
||||
|
||||
\subsection version15 1.5 September 21 2014
|
||||
\subsection version150 1.5.0 September 21 2014
|
||||
- Calculation with complex numbers.
|
||||
- Fixed command line version.
|
||||
- Miscellaneous bug fixed.
|
||||
@@ -360,7 +372,7 @@
|
||||
- Documentation including class diagrams in HTML format.
|
||||
- Scripts for porting and building the source.
|
||||
|
||||
\subsection version14 1.4 August 24 2014
|
||||
\subsection version140 1.4.0 August 24 2014
|
||||
- New math engine based on Sun Microsystems fdlibm (64 bit IEEE 754).
|
||||
- Support for positional numeral systems including binary, octal and hexadecimal.
|
||||
- Added pure command line version (CLI) as addition to the stand-alone version.
|
||||
@@ -377,7 +389,7 @@
|
||||
\subsection version131 1.3.1 August 08 2014
|
||||
- AROS i386 version released.
|
||||
|
||||
\subsection version13 1.3 August 06 2014
|
||||
\subsection version130 1.3.0 August 06 2014
|
||||
- All trigonometric and hyperbolic functions are now supported.
|
||||
- Runs in console window. amath no longer depends on a shell.
|
||||
- Hardened code. amath is no longer a beta version.
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse excosecant function in a syntax tree.
|
||||
* @details
|
||||
* More info on the excosecant function is available at [Wikipedia]:
|
||||
* More info on the excosecant function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Excosecant
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse exsecant function in a syntax tree.
|
||||
* @details
|
||||
* More info on the exsecant function is available at [Wikipedia]:
|
||||
* More info on the exsecant function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Exsecant
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#include "arcchord.h"
|
||||
|
||||
ArcChordNode::ArcChordNode(ExpressionNode* expression, char* text, char* sys) :
|
||||
FunctionNode(expression, text, sys)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionNode* ArcChordNode::Create(ExpressionNode* expression, char* text, char* sys)
|
||||
{
|
||||
return new ArcChordNode(expression, text, sys);
|
||||
}
|
||||
|
||||
Number* ArcChordNode::Evaluate()
|
||||
{
|
||||
result = expression->Evaluate()->ArcChord();
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_FUNCTION_ARCCHORD_H
|
||||
#define AMATH_FUNCTION_ARCCHORD_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
/**
|
||||
* @brief An inverse chord function in a syntax tree.
|
||||
* @details
|
||||
* More info on the inverse chord function is available at Wikipedia:
|
||||
* https://en.wikipedia.org/wiki/Chord_(geometry)
|
||||
*
|
||||
*/
|
||||
class ArcChordNode : public FunctionNode
|
||||
{
|
||||
public:
|
||||
explicit ArcChordNode(ExpressionNode* expression, char* text, char* sys);
|
||||
static FunctionNode* Create(ExpressionNode* expression, char* text, char* sys);
|
||||
Number* Evaluate();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -27,15 +27,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_FUNCTION_ARCOSINE_H
|
||||
#define AMATH_FUNCTION_ARCOSINE_H
|
||||
#ifndef AMATH_FUNCTION_ARCCOSINE_H
|
||||
#define AMATH_FUNCTION_ARCCOSINE_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
/**
|
||||
* @brief A arccosine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the arccosine function is available at [Wikipedia]:
|
||||
* More info on the arccosine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Arccosine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief A arccosecant function in a syntax tree.
|
||||
* @details
|
||||
* More info on the arccosecant function is available at [Wikipedia]:
|
||||
* More info on the arccosecant function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Arccosecant
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief A arccotangent function in a syntax tree.
|
||||
* @details
|
||||
* More info on the arccotangent function is available at [Wikipedia]:
|
||||
* More info on the arccotangent function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Arccotangent
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse coversed cosine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the coversed cosine function is available at [Wikipedia]:
|
||||
* More info on the coversed cosine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Covercosine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse coversed sine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the coversed sine function is available at [Wikipedia]:
|
||||
* More info on the coversed sine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Coversine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse hacoversed cosine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the hacoversed cosine function is available at [Wikipedia]:
|
||||
* More info on the hacoversed cosine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Hacovercosine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse hacoversed sine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the hacoversed sine function is available at [Wikipedia]:
|
||||
* More info on the hacoversed sine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Hacoversine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse haversed cosine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the haversed cosine function is available at [Wikipedia]:
|
||||
* More info on the haversed cosine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Havercosine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse haversed sine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the haversed sine function is available at [Wikipedia]:
|
||||
* More info on the haversed sine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Haversine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief A arcsecant function in a syntax tree.
|
||||
* @details
|
||||
* More info on the arcsecant function is available at [Wikipedia]:
|
||||
* More info on the arcsecant function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Arcsecant
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief A arcsine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the arcsine function is available at [Wikipedia]:
|
||||
* More info on the arcsine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Arcsine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief A arctangent function in a syntax tree.
|
||||
* @details
|
||||
* More info on the arctangent function is available at [Wikipedia]:
|
||||
* More info on the arctangent function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Arctangent
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse versed cosine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the versed cosine function is available at [Wikipedia]:
|
||||
* More info on the versed cosine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Vercosine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief An inverse versed sine function in a syntax tree.
|
||||
* @details
|
||||
* More info on the versed sine function is available at [Wikipedia]:
|
||||
* More info on the versed sine function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Versine
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
/**
|
||||
* @brief A ceiling function in a syntax tree.
|
||||
* @details
|
||||
* More info on the ceiling function is available at [Wikipedia]:
|
||||
* More info on the ceiling function is available at Wikipedia:
|
||||
* https://wikipedia.org/wiki/Ceiling_function
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#include "chord.h"
|
||||
|
||||
ChordNode::ChordNode(ExpressionNode* expression, char* text, char* sys) :
|
||||
FunctionNode(expression, text, sys)
|
||||
{
|
||||
}
|
||||
|
||||
FunctionNode* ChordNode::Create(ExpressionNode* expression, char* text, char* sys)
|
||||
{
|
||||
return new ChordNode(expression, text, sys);
|
||||
}
|
||||
|
||||
Number* ChordNode::Evaluate()
|
||||
{
|
||||
result = expression->Evaluate()->Chord();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*-
|
||||
* Copyright (c) 2014-2017 Carsten Sonne Larsen <cs@innolan.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*
|
||||
* Project homepage:
|
||||
* http://amath.innolan.net
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef AMATH_FUNCTION_CHORD_H
|
||||
#define AMATH_FUNCTION_CHORD_H
|
||||
|
||||
#include "node.h"
|
||||
|
||||
/**
|
||||
* @brief A chord function in a syntax tree.
|
||||
* @details
|
||||
* More info on the chord function is available at Wikipedia:
|
||||
* https://en.wikipedia.org/wiki/Chord_(geometry)
|
||||
*
|
||||
*/
|
||||
class ChordNode : public FunctionNode
|
||||
{
|
||||
public:
|
||||
explicit ChordNode(ExpressionNode* expression, char* text, char* sys);
|
||||
static FunctionNode* Create(ExpressionNode* expression, char* text, char* sys);
|
||||
Number* Evaluate();
|
||||
};
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user