C++Guns – RoboBlog

24.01.2019

Installing gcc, g++ and gfortran 8 from source

Filed under: Allgemein — Tags: , , , — Thomas @ 22:01

The procedure is quite the same as for gcc 4.8 as you can see in my older post Installing gcc, g++ and gfortran 4.8 from source Read the manual. Download, unpack, switch dir, download, unpack, link. $ wget ftp://ftp.gwdg.de/pub/misc/gcc/snapshots/LATEST-8/gcc-8-20190118.tar.xz $ xz -d gcc-8-20190118.tar.xz $ tar xf gcc-8-20190118.tar $ gcc-8-20190118/ $ wget ftp://ftp.gmplib.org/pub/gmp-6.1.2/gmp-6.1.2.tar.bz2 $ tar xjf […]

20.04.2018

C++ Guns: Levenshtein-Distanz - Teil 1

Filed under: Allgemein — Tags: — Thomas @ 07:04

Die Levenshtein-Distanz (auch Editierdistanz) zwischen zwei Zeichenketten ist die minimale Anzahl von Einfüge-, Lösch- und Ersetz-Operationen, um die erste Zeichenkette in die zweite umzuwandeln. Die Laufzeit Komplexität liegt bei quadratisch. Wie schnell ist das? Getestet werden 1000 Sequencen mit 200 Zeichen Länge. Die erste Implementierung von Wikipedia lasse ich im Debug Modus laufen und komme […]

11.05.2017

C++ Guns - Why isn't there a swap function in Fortran and C?

Filed under: Allgemein — Tags: , , — Thomas @ 09:05

Because Fortran and C sucks. To implement a generic swap function which works for any type and any custom type, one needs templates. Think about usually variables which store a value. Templates are variables which store types. But Fortran and C do not have template techniques. So one must implement a swap function for every […]

26.01.2016

Evaluation of logical operations

Filed under: Allgemein — Tags: , , — Thomas @ 21:01

Spass mit dem Standard. Aus dem Fortran 90/95 Standard [1] Kapitel 7.1.7.6. Evaluation of logical intrinsic operations The rules given in 7.2.4 specify the interpretation of logical intrinsic operations. Once the interpretation of an expression has been established in accordance with those rules, the processor may evaluate any other expression that is logically equivalent, provided […]

29.05.2015

warning: conversion to 'float' from 'int' may alter its value [-Wconversion] (Bug of the day 7)

Filed under: Allgemein — Tags: , , — Thomas @ 22:05

Another bug of the day :D You can do the following float var = float(vari); // yes I know I'm loosing precision int var = int(std::floor(varf)) // yes I know interger can overflow int var = qFloor(varf) // Qt version Same for double. warning: comparison between signed and unsigned integer expressions [-Wsign-compare] Tricky one. Usually […]

20.05.2015

-1 (Bug of the day 5)

Filed under: Allgemein — Tags: , — Thomas @ 19:05

vector vecB; vecB.resize(vecA.size()-1); for(size_t i = 0; i < vecA.size(); ++i) { ... vecB[i] = value ... } Na, wer findet ihn? Bei so etwas findet ich QT's QVector wieder besser als den Standard c++ vector. Qt macht zumindest bei Debug Einstellung eine Bereichsüberprüfung. Ausser es wird die at() Funktion statt den operator() benutzt. Dann […]

16.05.2015

integer overflow debugger trap

Filed under: Allgemein — Tags: , — Thomas @ 08:05

Benutzt man 16bit Integer statt 32bit um Speicher zu sparen und seine cache misses zu optimieren, läuft man Gefahr den Zahlenbereich von -32768 bis +32767 zu verlassen. So wie es für Floatingpoint Zahlen Überprüfungen auf over/underflow etc gibt, die ein Signal werfen bzw den Compiler anspringen lassen, so gibt es das auch für Integer. Ist […]

18.02.2015

rosettacode - Simple moving average

Filed under: Allgemein — Tags: , , — Thomas @ 12:02

http://rosettacode.org/wiki/Averages/Simple_moving_average#C.2B.2B The original rosetta C example shows the usage of variable function arguments. The C++ example shows how to implement a circular buffer. They are confusing and inefficient. My Version shows how to implement a simple moving average using modern c++ techniques. #include < iostream > #include < vector > class SMA { public: SMA(int […]

02.02.2015

more crazy C

Filed under: Allgemein — Tags: — Thomas @ 09:02

#include #define CACHE 256 enum { h_unknown = 0, h_yes, h_no }; unsigned char buf[CACHE] = {0, h_yes, 0}; int happy(int n) { int sum = 0, x, nn; if (n < CACHE) { if (buf[n]) return 2 - buf[n]; buf[n] = h_no; } for (nn = n; nn; nn /= 10) x = nn […]

02.01.2015

raw speed of C using OO with C++

Filed under: Allgemein — Tags: , , — Thomas @ 20:01

Programs written in C are very very fast. Those written in C++ can be slower due to the fact that copying object is not alway easy as copying an array of numbers. One have to call the copy constructor maybe with side effects like allocate some space. The language C++ is full backwards compatible to […]

Older Posts »

Powered by WordPress