- 1
Россия победила в XXII зимних Олимпийских играх.
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+142
Россия победила в XXII зимних Олимпийских играх.
+36
#include <iostream>
#include <cmath>
struct Point3D
{
float x,y,z;
Point3D () {}
Point3D (float x, float y, float z) : x(x), y(y), z(z) {}
Point3D& operator -= (const Point3D& p) { x-=p.x; y-=p.y; z-=p.z; return *this; }
Point3D operator - (const Point3D& p) const { Point3D p2(*this); return (p2-=p); }
Point3D& operator *= (const float f) { x*=f; y*=f; z*=f; return *this; }
Point3D operator * (const float f) const { Point3D p2(*this); return (p2*=f); }
};
float Dot (const Point3D& p1, const Point3D& p2) { return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z; }
struct Face
{
Point3D n;
float nc;
float Dist (const Point3D& p) const { return Dot(p,n)-nc; }
};
int show_float(float src)
{
union
{
int i;
float f;
} u;
u.f = src;
return u.i;
}
float from_int(int src)
{
union
{
int i;
float f;
} u;
u.i = src;
return u.f;
}
template<typename T>
T& operator<<(T& str, const Point3D& p)
{
str << std::hex << "Point3D(from_int(0x" << show_float(p.x) << "), from_int(0x" << show_float(p.y) << "), from_int(0x" << show_float(p.z) << "))";
return str;
}
struct SPoint
{
Point3D p;
bool DoCorrectFace(const Face& face)
{
bool correct = true;
float j=1.0f;
Point3D np=p;
for (;;)
{
float ad = face.Dist(np);
if (ad<=0.0f)
break;
correct=false;
np = p - (face.n*(ad*j));
j += 1.0f;
}
p=np;
return correct;
}
};
using namespace std;
int main()
{
cout << "Hello World!" << endl;
SPoint spoint;
spoint.p = Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0));
cout << "Initial p:" << endl;
cout << spoint.p << endl;
cout << "Corrected:" << endl;
Face f;
f.n = Point3D(from_int(0x3d6cc83b), from_int(0x3f0e8841), from_int(0x3f5422bd));
f.nc = from_int(0x41bac3dc);
bool result = spoint.DoCorrectFace(f);
cout << spoint.p << endl;
cout << "Done: " << result << endl;
return 0;
}
говно в gcc
g++ (rev5, Built by MinGW-W64 project) 4.8.1
вывод в -O2 -DNDEBUG :
Hello World!
Initial p:
Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
Corrected:
Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d1))
Done: 0
вывод в -O3 -DNDEBUG:
Hello World!
Initial p:
Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
Corrected:
Point3D(from_int(0x41c6940e), from_int(0x427352a6), from_int(0xc166e2d0))
Done: 0
внимание вопрос: может ли быть такое, что DoCorrectFace не изменил точку ни на бит, но вернул false? В gcc может!
+50
CleverPtr(const int other)
{
this->~CleverPtr();
new(this) CleverPtr();
//operator =(other);
}
Решение крестопроблем в крестостиле гейдевщиков:
http://ideone.com/wIPzzc
+152
$('<div />').html($title.html()).text();
Нашел у себя, пытался вспомнить к чему данный финт ушами
−99
>>> max
<built-in function max>
>>> max.__call__
<method-wrapper '__call__' of builtin_function_or_method object at 0x01D72080>
>>> max.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x022D2730>
>>> max.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x022D29B0>
>>> max.__call__.__call__.__call__.__call__
<method-wrapper '__call__' of method-wrapper object at 0x022D2970>
>>> max.__call__.__call__.__call__.__call__(1,2,3)
3
We need to go deeper.
+57
for(int loshdka_skachi = 0; loshadka_skachi < pyati_raz; loshadka_skachi += prig_skok){
оттуда
конардо посвящается
+155
<form onsubmit="return true && checkXML(name)">
и причем здесь true
+46
vector<int> v = {1, 4, 6};
cout << "(";
copy(v.begin(), v.end(), ostream_iterator<int>(cout, ", "));
cout << ")";
http://ideone.com/2j2jQG
+41
for (std::vector<SomeClass::SmartPtr>::iterator i = candidates.begin ();
i != candidates.end (); )
{
if ((*i)->getArea ().intersect (thisArea))
{
// label is inside the area.
++i;
}
else
{
// label must be removed
std::iter_swap (i, candidates.end () - 1);
candidates.pop_back ();
}
}
Не совсем ясны были мотивы человека, написавшего это. Этот код вообще не работает и не сразу и поймешь что тут к чему.
+149
$->db->select_value('select now()');
наверное в мускуле какое-то другое время