Skip to content

Instantly share code, notes, and snippets.

View kaityo256's full-sized avatar
🤖
I, Robot

Hiroshi Watanabe kaityo256

🤖
I, Robot
  • Keio University
  • Japan
View GitHub Profile
@kaityo256
kaityo256 / test.cpp
Created May 25, 2017 09:50
An example code causing an internal error
#include <stdio.h>
typedef double v4df __attribute__((vector_size(32)));
typedef double v8df __attribute__((vector_size(64)));
template <class T>
void func(T r) {
double *a = (double*)(&r);
for(int i=0;i < sizeof(T)/sizeof(double);i++){
printf("%.10f ",a[i]);
}
printf("\n");
@kaityo256
kaityo256 / test.cpp
Created June 6, 2017 08:06
x87 test
#include <math.h>
double
func(void){
const int N = 1000000;
const double s = 2.0*M_PI/static_cast<double>(N);
double x = 0.0;
double y = 0.0;
for(int i=0;i<N*100;i++){
y += sin(x);
x += s;
@kaityo256
kaityo256 / test.cpp
Created July 10, 2017 06:11
Compilation takes too long
#include <stdio.h>
const int N = 100000000;
int
main(void){
static int a[N] = {};
printf("%d\n",a[0]);
}
@kaityo256
kaityo256 / test.cpp
Created July 14, 2017 00:10
A sample using ternary operators
#include <stdio.h>
int
main(void){
int a = 1, b = 2;
int c[] = {4,5, (a>b? 1:2)};
int d[(a>b? 1:2)];
printf("%d\n",c[2]); // = > 2
printf("%d\n",sizeof(d)); // => 8
}
@kaityo256
kaityo256 / test2.cpp
Created July 14, 2017 00:27
A sample using ternary operators
#include <stdio.h>
struct Hoge{
Hoge(int a){
printf("int %d\n",a);
}
Hoge(double d){
printf("double %f\n",d);
}
};
int
@kaityo256
kaityo256 / test3.cpp
Created July 14, 2017 00:43
A sample using ternary operators
#include <stdio.h>
void func(int a){
printf("int %d\n",a);
}
void func(unsigned int a){
printf("unsigned int %d\n",a);
}
int
main(void){
int a = 2, b = 1;
@kaityo256
kaityo256 / test4.cpp
Created July 14, 2017 00:55
A sample using ternary operators
#include <iostream>
int
main(void){
int a = 2, b = 1;
auto x = (a > b? 2 : 1.0);
std::cout << x << std::endl; // => 2
std::cout << sizeof(x) << std::endl; // => 8
}
@kaityo256
kaityo256 / test5.cpp
Created July 14, 2017 02:05
A sample using ternary operators
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <cxxabi.h>
struct Super{
virtual void hello(void){
printf("I am Super.\n");
}
};
@kaityo256
kaityo256 / test6.cpp
Last active July 14, 2017 04:47
A sample using ternary operators
#include <iostream>
int
main(int argc, char ** argv){
(argc > 1? std::cout:std::cerr) << "Hello" << std::endl;
}
@kaityo256
kaityo256 / test.cpp
Created July 18, 2017 07:03
Operations to boolean
#include <stdio.h>
int
main(void){
bool t = true;
printf("%d\n",t << 1); //=> 2
printf("%d\n",++t); //=> 1
printf("%d\n",t); //=> 1
int i = 1;
printf("%d\n",i << 1); //=> 2
printf("%d\n",++i); //=> 2