I have a simple question.
How can I make a program that can operate on huge float numbers without external libraries?
I got the idea to actually throw a whole library into my source code.
I found this: https://github.com/panks/BigInteger/blob/master/BigIntegerSingleFile.cpp
However when I'm dividing simple numbers like 20/12 it's always giving me "0".
So I decided to use GMP instead of BigInt but I have no idea how to include it in my code without using #include statement. My code needs to use only standard libraries.
Related
I'm trying to build a portable project that uses a library and that library uses GMP. I am wondering if it is possible to use a statement like #include "gmpxx.h" with GMP's code in my project's directory.
Yes, as Marc Glisse pointed out, if performance is not so important to you, and you are not calculating with very very large numbers, GMP has a small footprint library-within-the-library version called "mini-gmp" which is almost fully compatible with the GMP interface, comprising calculations on natural numbers (mpn), integers (mpz), and rationals (mpq), see here and here for details. Almost all issues with mini-gmp have been fixed.
You don't ever install mini-gmp, basically you #include "mini-gmp.c" in your code (and #include "mini-mpq.c" if rational numbers required) and you are ready to go. Or just compile mini-gmp.c as a separate compilation unit and use the declarations in mini-gmp.h. Also, there's a test suite in the directory you may run with make.
Note, though, that if your application is mission-critical you may run into problems because all microarchitecture optimizations and code for arithmetic on asymptotically large numbers are not included in mini-gmp.
I need to define functions in c++ code to be user defined. Basically that he writes the function in form of a string which is exact c++ code, then use that function in the very next line of code.
I have tried to append output to a file which is imported, but it obviously failed
You simply cannot do it. C++ code can not be interpreted at run-time. You may want to try Qt/QML which will give an opportunity to run a javascript code or an entire QML file from network/string or any other method which can deliver your code to the host application.
I assume you are talking about a pure function such as a mathematical formula.
To my knowledge, what you ask is not possible without
a) writing your own parser, that effectively creates functions from strings or
b) using external libraries - a quick google search brought be to this library that seems to provide the functionality you are looking for. I have no personal experience with it, though.
As #Useless pointed out, "editing" the code after compilation is not intended in a compiled language as c++. This could be tricked by having a second code compiled and executed in the background; this, however, seems rather unelegant and would rely on additional threads, compilers and the operating system.
I'm coding a program with a function that makes compilations quite long as it needs its own library. I don't see myself changing this function as it does what I expect from it and I only call it incidentally. This is why I'd like to know if there is a way to compile it once and for all in something like a library, including this library in someway in my program so it can have access to this specific function. I was also thinking about coding it in a separated program and using system(commands) to run it but I was wondering if there was a neater way of doing it. Is there something?
There is a Matlab function (h5write) that lets the user write output files in hdf5 format. This seems to work nicely when using the Matlab environment and Matlab files. However, when I try to generate C++ code out of the Matlab files, a conversion error arises. It appears that the code generator (Matlab Coder) cannot convert the h5write operation into C++ code.
Is there any way of getting around this issue? Efficiency is also important here since the data sets that need to be stored by the generated C++ executable are fairly large. If anybody could help me out here, it would make my day! :-)
MATLAB currently provide an interface for converting the code for h5write into C++ code. That being said, you can use MATLAB compiler to build an executable or dll. You can use this in your C++ code, but you will always need the MCR. If space is not a constraint, you can do this.
Otherwise, you can use the HDF5 API (http://www.hdfgroup.org/HDF5/doc/cpplus_RM/) and write code for writing into HDF5 file format and then use MATLAB Coder to link and compile.
I need a C++ algebra library in order to use in my project. At the beginning I thought I can write one, but then I realized I was unsuccessfully trying to reinvent the wheel and wasting my precious time.
For arithmetic issues I found GMP Library (you know, for unlimited arithmetic calculations), and tools for other kind of tasks (standard C++ library seemed quite enough for pseudo-random number generation). However, I couldn't find a suitable one for algebraic works.
There are linear algebra libraries (such as Armadillo) but I'm not sure I need such a library. I want to summarize my needs.
#include <string>
#include <somelibrary.h>
int main(){
std::string str = "3*x^3+2*x^2+x+sqrt(x)*x^(1/3)";
algebraic_expression* exp = new algebraic_expression(str);
}
I want to have a tree from such an expression. Lets say it will return a std::vector or C style array with some information. For example (considering the example above) exp[0] will be "3*x^3", or maybe exp[0]["base"]="x".And why do I need this? Actually I can do the similar things by means of using RegEx, but sometimes I cannot handle it for example 3*x^0 is simply 3, I cannot print 3*x^0 because it is meaningless I want to have 3 (just like 3*x^1 is 3*x). Or (3-3)*5*2 will return 0, etc...
Thank you for your help.
You should look for 'CAS' (Computer Algebra System) . I can suggest you two:
Ginac http://www.ginac.de/
Giac: http://www-fourier.ujf-grenoble.fr/~parisse/giac.html
An example program with Giac: http://www-fourier.ujf-grenoble.fr/~parisse/giac_us.html#First%20example
Giac also comes with a GUI application called XCAS. It's a very powerful tool you should give it a try.
I've used LAPACK for my Master thesis program for 3D algebra calculations.
link : http://www.netlib.org/lapack/ link of c++ version of
library : http://www.netlib.org/lapack++/