Arbitrary Precision Arithmetic in C++ (W10)

I’ve been working through About - Project Euler for the last week. I’ve reached the point where the ability to perform arithmetic on variables with arbitrary precision and size would be convenient. I’m trying to decide which is the most practical way to gain this functionality.

  • GMP
    My initial Google search turned up that this is just about the gold standard for addressing this problem. Inconveniently, there isn’t much (any?) support to compile for Windows. I can certainly switch to a Linux environment, but it would be more convenient to keep to Windows for now.

  • MPIR
    My understanding is that this is a port of GMP for Windows. I went as far as getting it installed through vcpkg, but it seems like their domain expired (?) and I’m not able to get any documentation for how to actually use it. Has this project been replaced by something else that I haven’t found?

  • Don’t use c++
    Using something like python would take care of this for me quite handily.

My main interest is in embedded development, so I feel like switching to python isn’t the ideal choice for me here. How would this get addressed in the real world?

Any and all input is greatly appreciated.

1 Like

I read that MPIR was designed to be compatible with GMP (obviously), so it looks like I can use the GMP docs as a reference.

I also used C++ and GMP to solve some Project Euler questions… but on Linux.

Using C++ libraries on Windows in general is painful, especially with the Microsoft tools.

You’ll have more luck with MinGW and MSYS - then you can ./configure --enable-cxx && make install.

--enable-cxx installs the gmpxx C++ interface, which includes operator overloads and wrapper classes for all the GMP types, so you don’t need to call the gmp_* functions explicitly (C++ Interface General (GNU MP 6.2.1)).

3 Likes

I’ve started looking into IDEs in Linux. Hooooo boy.

Can I ask what you use/used?

Sublime text and a makefile.

1 Like

gmp is installable through vcpkg on windows

1 Like

I currently use QtCreator for desktop C++ applications, but it really doesn’t seem configurable enough for embedded programming.
For that, I use gedit (gnome) or Pluma (Mate) as text editors with command-line tools or Arduino.

I’ve heard that VSCode is pretty darn flexible to whatever you want to do. So if you don’t mind your IDE being Chromium based, that may be a good choice as well.

P.S. QtCreator is on-par with (if not better than) VisualStudio for syntax highlighting and parsing. It recurssively scans your project directory and allows you to follow functions or structures to wherever they are implemented. It also doesn’t require you to use the Qt library in your projects, despite its name.

1 Like

VSCode … (well, actually I’m using code server here which isn’t exactly the same but close enough).

People mostly tend to just stick to libraries and headers installed system wide and would use basic hand crafted make and/or cmake for their stuff.

Lots of old timers and seasoned devs would still just use a text editor (vim/emacs) with various plugins and exotic keyboard shortcuts… and a terminal alongside as opposed to an ide with an integrated debugger and build/run/test/vcs/dependencymanagement/and rest of the kitchen sink built in.

This whole time I assumed it wasn’t. That would explain why MPIR didn’t seem active anymore.

I’ll look into that when I get home!

I looked at qtcreator and honestly glossed over it because I sort of assumed it was “only” for qt. Definitely gonna give that another look!

So far I’m liking kdevelop quite a bit. Interface was very intuitive for me.

As for embedded development, I like to use hardware- specific IDEs when projects get more involved. It can be unpleasant if you switch hardware mid project, but for personal projects that’s a lot less of a problem. I really liked STM’s utility to initialize pins.

My software developer friends that do use vim pretty much universally say “modern IDEs are wonderful, you should use those.” Then they note that nearly all of the people they work with don’t use an IDE :man_shrugging:

1 Like

as a full time vim user theres two things i cant stand:

People who make fun of other peoples editor choices

And emacs users

2 Likes