This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ios> | |
#include <iomanip> | |
#include <cstring> | |
#include <cstdlib> | |
int main(int argc, char **argv) | |
{ | |
if (argc != 2) { | |
std::cerr << "Usage: " << (argc ? argv[0] : "double") << " <number>\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Public Function arrayAddress(ByRef arr() As Double) As Long | |
arrayAddress = VarPtr(arr(0)) | |
End Function | |
Public Sub investigateArrays() | |
Dim d(0 To 9) As Double | |
Dim x() As Double | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXX=g++ | |
CXXOPTS=-std=c++11 -pedantic -Wall -Wextra -Werror -static-libgcc -static-libstdc++ | |
OPTOPTS=-O3 -fno-exceptions -fno-rtti -ffast-math -mfpmath=387 -msse3 -mtune=core2 -funroll-loops -s | |
DLLOPTS=-shared | |
LINKOPTS=-Wl,--add-stdcall-alias | |
LOG= | |
#LOG=-DLOGGING="log.txt" | |
callback.dll: callback.o | |
$(CXX) $(CXXOPTS) $(LOG) $(OPTOPTS) $(DLLOPTS) -o callback.dll callback.o $(LINKOPTS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class T> | |
using auto_buf = std::unique_ptr<T[], void(&)(void*) noexcept>; | |
template<class T> | |
auto_buf<T> make_auto_buf(std::size_t n) noexcept | |
{ | |
return auto_buf<T>(static_cast<T*>(std::malloc(n * sizeof(T))), std::free); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "tpow.hpp" | |
int main() | |
{ | |
static_assert(noexcept(tpow<5>(5)), "tpow<int, N> not noexcept"); | |
std::cout << "5^5 = " << tpow<5>(5) << '\n'; | |
static_assert(noexcept(tpow<4>(2.3)), "tpow<double, N> not noexcept"); | |
std::cout << "2.3^4 = " << tpow<4>(2.3) << '\n'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#hello world | |
Fun with **R**! | |
````{r} | |
rnorm(100) | |
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(555) | |
pop.1 <- data.frame(x=rnorm(n=25, mean=5, sd=3), | |
y=rnorm(n=25, mean=3, sd=2)) | |
pop.2 <- data.frame(x=runif(n=25, min=6, max=10), | |
y=runif(n=25, min=3, max=8)) | |
pop.3 <- data.frame(x=rnorm(n=25, mean=4, sd=1.2), | |
y=rnorm(n=25, mean=7, sd=2)) | |
pop <- rbind(pop.1, pop.2, pop.3)[sample(nrow(pop.1) * 3),] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public service announcement: use extreme caution when compiling under g++ with -msseX and returning a std::pair<double, double>, or the structural equivalent, by value. It will optimize to a movapd, which works wonderfully as long as you're returning into a 16-bit aligned address. But you'll mysteriously explode in a shower of body parts if calling into, say, a DLL from external code (say, Excel VBA) with a less-strictly aligned stack. | |
No, I didn't just spend 5 hours tracking that one down... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <cstddef> | |
#include <algorithm> | |
#include <iostream> | |
#include <iomanip> | |
template<class T> | |
inline std::unique_ptr<unsigned char[]> to_bytes(const T& item) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXX=g++ | |
CXXOPTS=-std=c++11 -pedantic -Wall -Wextra -Werror -static -static-libgcc -static-libstdc++ | |
OPTOPTS=-O3 -fno-rtti -ffast-math -mfpmath=387 -msse3 -mtune=core2 -funroll-loops -s | |
DLLOPTS=-shared -DDLL | |
LINKOPTS=-Wl,--add-stdcall-alias | |
LOG= | |
#LOG=-DLOGGING="log.txt" | |
thread_engine.dll: thread_engine.cpp | |
$(CXX) $(CXXOPTS) $(LOG) $(OPTOPTS) $(DLLOPTS) -o thread_engine.dll thread_engine.cpp $(LINKOPTS) |