rechne.exe • Integration


JPlotter is a Java-based program with a graphical user interface which uses the rechne library.
The program allows for plotting of mathematical functions and provides many options, such as:
  • plotting complex functions with real and imaginary part (or amplitude and phase)
  • derivating function
  • integrating function
  • performing Discrete Fourier analysis
  • calculating areas between functions
  • finding zeros / extrema of functions
  • many more...
Example plot of a complex function

JPlotter also has a number of integrated tools:
  • solving linear equation systems
  • calculating (complex) zeros of a polynomial
  • analyzing a vector (Discrete Fourier Transformation, different vector norms)
  • analyzing a matrix (Eigen values, inverse matrix, matrix norms)
  • Rechne Console: this is basically a Java fontend for rechne.exe

JPlotter Website:
Rechne Console

Shell commands

The rechne.exe binary can be called from command-line and hence can be integrated into scripts (shell scripts on Linux or batch scripts on Windows). If rechne.exe is called with arguments it tries to process them and terminates afterwards where if rechne.exe is called without arguments, it starts in the interactive shell mode.
All inputs known from the shell mode can be passed as command-line arguments.

Some examples:
» Call with command-line arguments (brackets may need to be escaped):
> ./rechne.exe -v 12.8*sin\(1.5*Pi\)
» Pipe echos:
> echo "sqrt(144)+19*ln(5)" | ./rechne.exe -v
» Calculate the SHA-512 sum of rechne.exe as a decimal number:
> sha512sum rechne.exe | cut -c -128 | ./rechne.exe bn -q -ilow -odec
» Shell script to plot data pairs of the function si(x)*cos(x)*sig(x) using gnuplot:
for i in {-100..100} ; do
  ./rechne.exe -q si\($i/10\)*cos\($i/10\)*sig\($i/10\) >> datapair
  echo -n " " >> datapair
  ./rechne.exe -q \($i\)/10 >> datapair
  echo >> datapair
gnuplot -persist << EOF
  set title 'si(x)*cos(x)*sig(x)'
  set grid
  plot "datapair" using 2:1
rm -f datapair

gnuplot frame


All compiled rechne.exe functions (except for the main function) are contained in the library file librechne.a. This allows for an integration of rechne.exe functions in C/C++ projects. The download archiv comes with a header file librechne.h that contains structures and prototypes for rechne.exe function calls.
The Makefile automatically creates this library file (in the lib folder) on compilation (see Installation).

Example of a C program that includes librechne: #include <stdio.h>
#include <string.h>
#include "librechne.h"

int main() {
  /* calculation result (complex number) */
  CN res;

  char input_buffer[1024];

  /* rechne configuration */
  extern RECHNE_CFG config;

  /* return value */
  int ret;

  /* initialize rechne configuration */

  /* calculate user inputs */
  printf("type term (e.g. '12.7*42') or 'exit')\n");
  for ( ; ; ) {
    fgets(input_buffer, sizeof(input_buffer), stdin);

    /* remove line break at the end */
    input_buffer[strlen(input_buffer) - 1] = 0;
    if (strcmp(input_buffer, "exit") == 0)

    /* call rechne.exe function */
    ret = subcalc(input_buffer, &res);

    /* evaluate return value */
    if (ret == 0)
      printf("result is: %f+%f*i\n", res.real, res.img);
      printf("error %u occured\n", __errno);

  return 0;

Copy librechne.h (comes with the librechne download archive or is in the lib folder after "make") to the source directory (next to myprog.c) and compile with: gcc -Wall myprog.c -L./lib -lrechne -lm -o myprog
Replace "./lib" with wherever librechne.a is located.

Some code snippets: » Binary numbers as input: init_cfg(&config);
config.in_num_sys = 2u;
subcalc("110101.1101*sin(10101111.11)", &res);

» Hex numbers as input and increase verbosity (will print intermediate steps): init_cfg(&config);
config.in_num_sys = 16u;
subcalc("A7C45F.3C+9F8A", &res);

» Calculate with complex numbers: init_cfg(&config);
subcalc("2*e^(1.8*Pi*i)/(2-3*i)", &res);


With JNI (Java Native Interface) rechne.exe functions (that is C code) can be called from Java code.
That allows for the calculation of a result (as a double value) for any given calculation string in Java. The advantage of calling C code is that processing is very fast. The dll file rechne.dll (Windows 32 Bit or Windows 64 Bit) already has the JNI functions enabled and can be used for Java projects on Windows. Equivalently the shared object file can be used on Linux (32 Bit).

The Makefile automatically creates the dll file on Windows or the shared object file on Linux but not with JNI enabled. This is because compilation requires the JNI header files from the Java Development Kit and the path is different on every system (or there might be no JDK installed at all).

To enable the compilation of the JNI module of rechne.exe (that are the files rechne_jni.c and rechne_jni.h) the Makefile has to be edited. Therefor read the comment and enable the following both lines in the Makefile:
# JNI is for calling native rechne.exe functions from Java code.
# See the JNI example on
# rechne_jni.h contains the JNI header (generated from javah).
# To enable JNI compilation uncomment the following two lines.
# Replace <PATH_TO_JDK> with the path of the JDK installation.
# Replace win32 with the current operating system.
#CINCL += -I<PATH_TO_JDK>/include -I<PATH_TO_JDK>/include/win32
Once again you only have to recompile rechne.exe with JNI enabled if you cannot use the precompiled libaries from the download folder for some reason.
After editing make clean and make again.

Now the following example shows how to call the native rechne.exe function from Java:
package de.jsteltze.rechne;

public class Rechne {
  static {
     * Load rechne.dll. The file must be within in the Java libary path.
     * You can set the shell variable LD_LIBRARY_PATH.
     * Check the property System.getProperty("java.library.path")

  public class RechneResult {

    // Return code, 0 indicates no error
    public int return_code;

    // Real and imaginary part of the result (as a complex number)
    public double real, img;

    public RechneResult(int return_code, double real, double img) {
      this.return_code = return_code;
      this.real = real;
      this.img = img;

   * This is the actual interface to the C code of rechne.exe.
   * See the source files rechne_jni.c and rechne_jni.h.
  public static native RechneResult rechne(String x);

  public static void main(String[] args) {
    // The -q option suppresses outputs from the rechne.exe C code
    // The -l option suppresses logging
    RechneResult res = rechne("-ql (2.4+18)*12+sin(3*Pi/4)");
    System.out.println("return code: " + res.return_code);
    if (res.return_code == 0) {
      System.out.println("result: " + res.real);

It is important that you DO NOT rename the Java class or relocate it (that is change the package name). Also you MUST NOT change the signature of the inner class RechneResult or relocate it and you MUST NOT change the signature of the native rechne function.
Otherwise it is likely that you will get a UnsatisfiedLinkError.
Have a look at rechne_jni.h (which is generated by javah) if you want a deeper understanding of how the interaction between Java and C code works.