The Lines of Code That Changed Everything

Bine, sunt zeci de mii de linii de cod in codecul jpeg sau in primul browser, dar anumite dintre ele sunt mai speciale :slight_smile:

Unele sunt banale, gen window.open('https://www.slate.com/') altele au ceva special.

double *NaiveDct_transform(double vector[], size_t len) {
  if (SIZE_MAX / sizeof(double) < len)
    return NULL;
  double *result = malloc(len * sizeof(double));
  if (result == NULL)
    return NULL;
  
  double factor = M_PI / len;
  for (size_t i = 0; i < len; i++) {
    double sum = 0;
    for (size_t j = 0; j < len; j++)
      sum += vector[j] * cos((j + 0.5) * i * factor);
    result[i] = sum;
  }
  return result;
}

De aici

O secventa de cod care mie imi place mult

float Q_rsqrt( float number )
{
	long i;
	float x2, y;
	const float threehalfs = 1.5F;

	x2 = number * 0.5F;
	y  = number;
	i  = * ( long * ) &y;                       // evil floating point bit level hacking
	i  = 0x5f3759df - ( i >> 1 );               // what the fuck? 
	y  = * ( float * ) &i;
	y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
//	y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed

	return y;
}
1 Like