Skip to content

Instantly share code, notes, and snippets.

View cpmech's full-sized avatar
🦀
Rusting

Dorival Pedroso cpmech

🦀
Rusting
View GitHub Profile
@cpmech
cpmech / seg_fault_does_not_happen.cpp
Last active July 1, 2022 00:12
Dangers of using C/C++ lambda functions (NO warnings from the compiler!)
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
const size_t NNODE = 3;
void print_x(size_t num_triangle, function<vector<double> const *(size_t, size_t)> get_x) {
for (size_t t = 0; t < num_triangle; t++) {
@cpmech
cpmech / evil-floating-point-compuattions.txt
Last active January 30, 2023 02:38
Float point numbers are evil. The answer should be 2; but we get 0
Evil Floating-Point Computations (using Mathematica 13.1)
Analytical
In[1]:= a={32 10^7,1,-1,8 10^7}
Out[1]= {320000000,1,-1,80000000}
In[2]:= b={4 10^7,1,-1,-16 10^7}
Out[2]= {40000000,1,-1,-160000000}
In[3]:= a b
Out[3]= {12800000000000000,1,1,-12800000000000000}
In[4]:= Total[a b]