- 1
Сумма = Цел(Окр(Сумма * 1000, 0, 1)) / 1000;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
Сумма = Цел(Окр(Сумма * 1000, 0, 1)) / 1000;
Или я мандаринов переел, или от этого портал должен открыться
+2
Дайте инвайт этому господину
https://habr.com/sandbox/125898/
0
const size_t page_num = 2000000;
const size_t page_size = sysconf(_SC_PAGE_SIZE);
assert(page_size == 4096);
const size_t buf_len = page_num * page_size;
size_t tmp = 0;
Того рот ебал, пыхамакаки в деле
+1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SQARESZ 3
void rotateclockwise(char *ptra, size_t sz)
{
char (*a_ar)[sz] = (void *)ptra;
char b_ar[sz][sz];
for (size_t y = 0; y < sz; y++)
{
for (size_t x = 0; x < sz; x++)
{
b_ar[y][x] = a_ar[sz-1-x][y];
}
}
memcpy(a_ar, b_ar, sz*sz);
}
void print_ar(char *ptra, size_t sz)
{
char (*a_ar)[sz] = (void *)ptra;
for (size_t y = 0; y < sz; y++)
{
for (size_t x = 0; x < sz; x++)
{
printf("%i ", a_ar[y][x]);
}
printf("\n");
}
}
int main()
{
char a[SQARESZ][SQARESZ] =
{
{1,2,3},
{4,5,6},
{7,8,9}
};
print_ar((char *)a, SQARESZ);
printf("\n");
rotateclockwise((char *)a, SQARESZ);
print_ar((char *)a, SQARESZ);
printf("\n");
rotateclockwise((char *)a, SQARESZ);
print_ar((char *)a, SQARESZ);
printf("\n");
rotateclockwise((char *)a, SQARESZ);
print_ar((char *)a, SQARESZ);
printf("\n");
rotateclockwise((char *)a, SQARESZ);
print_ar((char *)a, SQARESZ);
printf("\n");
return 0;
}
https://habr.com/post/317300/ В C++17 до сих пор нет нормальных многомерных массивов, которые были в Fortran начиная с Fortran 90
> UPD от 2016-12-10 14:03. Посмотрел на этот коммент от @selgjos, поэкспериментировал с компилятором и понял, что с помощью C99 VLA всё-таки можно добиться нужного мне эффекта.
> В общем, окей, в C есть нужные мне массивы. Как и в Fortran. А в C++ их по-прежнему нет.
+2
/*
x86-64 clang (trunk) -O3
https://godbolt.org/z/t8NDGG
#include <inttypes.h>
uint32_t saturation_add(uint32_t a, uint32_t b)
{
const uint64_t tmp = (uint64_t)a + b;
if (tmp > UINT32_MAX)
{
return UINT32_MAX;
}
return tmp;
}
*/
saturation_add:
mov edx, esi
mov eax, edi
add edi, esi
add rax, rdx
mov edx, 4294967295
cmp rax, rdx
mov eax, -1 // ЗАЧЕМ???
cmovbe eax, edi
ret
https://en.wikipedia.org/wiki/Saturation_arithmetic
Почему компиляторы до сих пор такое говно
0
protected setElementModel(formModel: any): any {
var self = this;
var workModel = jQuery.extend(true, {}, formModel, {
onSave: function (e) { e.preventDefault(); self._onSave(e); },
onSaveExit: function (e) { e.preventDefault(); self._onSaveExit(e); },
onCancel: function (e) { e.preventDefault(); self._onCancel(e); },
}
);
return self.setModel(workModel);
}
protected setModel(formModel: any): any {
return formModel;
}
typescript at its best
+4
typedef void proc();
proc nop{}
void swap(int *a, int *b) {*a^=*b^=*a^=*b;}
void sort_(int *arr, unsigned len)
{
(proc*[]){nop, swap}[*arr > arr[1]](arr, arr+1);
(proc*[]){nop, sort_}[len > 2](arr+1, len-1);
}
void sort(int *arr, unsigned len)
{
(proc*[]){sort_, nop}[len <= 1](arr, len);
(proc*[]){nop, sort}[len > 2](arr, len-1);
}
По поводу апнутого #19105.
Ветвление легко имитируеься массивом функий, цикол —– рукурсией. Получилось даже короче и понятнее чем обычный код.
+1
template<class T, class U> bool convertStrToInt(const char* str, int base, T &res, T def, U (*strto)(const char *, char **, int ))
{
char *endptr = NULL;
errno = 0;//man wants it
if ( ! str || *str == '\0' )
{
res = def;
return false;
}
U result = strto(str, &endptr, base);
if (errno == ERANGE || (*endptr != '\0') || ! *str) {
std::stringstream errorStr;
errorStr << "convertStrToInt failed ; string = '" << str << "' result ='" << result << "' endptr = '" << endptr << "' errno = '" << errno << "'";
res = def;
log_error("%s", errorStr.str().c_str());
return false;
}
res = static_cast<T>(result);
return true;
}
Преобразование строки в число
+2
<?php
function japanize($s) {
$syl = array('н',
'а','ка','са','та','на','ха','ма','я','ра','ва','га','дза','да','ба','па',
'и','ки','си','ти','ни','хи','ми','и','ри', 'ги','дзи', 'би','пи',
'у','ку','су','цу','ну','фу','му','ю','ру', 'гу','дзу', 'бу','пу',
'э','кэ','сэ','тэ','нэ','хэ','мэ','е','рэ', 'гэ','дзэ','дэ','бэ','пэ',
'о','ко','со','то','но','хо','мо','ё','ро','во','го','дзо','до','бо','по',
'кя','ся','тя','ня','хя','мя', 'ря', 'гя','дзя', 'бя','пя',
'кю','сю','тю','ню','хю','мю', 'рю', 'гю','дзю', 'бю','пю',
'кё','сё','тё','нё','хё','мё', 'рё', 'гё','дзё', 'бё','пё'
);
$modulo = count($syl);
$parts = str_split(substr(sha1($s), 0, 16), 2);
array_walk($parts, function(&$value, $key) use($syl, $modulo) {$value = $syl[intval($value, 16) % $modulo];});
return implode('', $parts);
}
echo japanize('bormand') . PHP_EOL;
Куд-кудах:
https://ideone.com/l3WdCD
0
[ERROR] The compilation of ocaml-base-compiler failed at "/home/me/.opam/opam-init/hooks/sandbox.sh build ./configure -prefix /home/me/.opam/ocaml-base-compiler.4.02.3 -with-debug-runtime".
#=== ERROR while compiling ocaml-base-compiler.4.02.3 =========================#
# context 2.0.0 | linux/x86_64 | | https://opam.ocaml.org#12c8601e
# path ~/.opam/ocaml-base-compiler.4.02.3/.opam-switch/build/ocaml-base-compiler.4.02.3
# command ~/.opam/opam-init/hooks/sandbox.sh build ./configure -prefix /home/me/.opam/ocaml-base-compiler.4.02.3 -with-debug-runtime
# exit-code 2
# env-file /tmp/opam-me-3195/ocaml-base-compiler-3195-d6d332.env
# output-file /tmp/opam-me-3195/ocaml-base-compiler-3195-d6d332.out
### output ###
# ./configure: line 195: rm: command not found
# ./configure: line 196: touch: command not found
# ../gnu/config.guess: line 35: sed: command not found
# ../gnu/config.guess: line 1364: mkdir: command not found
# ../gnu/config.guess: line 1364: mkdir: command not found
# : cannot create a temporary directory in /tmp
# [ERROR!] Cannot guess host type. You must specify one with the -host option.
^ ...И так там со всем.
Кто там хотел попробовать "NixOS"? Могу поделиться впечатлениями: если вы надеятесь, что в этой оси можно будет пользоваться привычными "autotools", "opam" и "cabal", то фиг там. Из-за сломанного FHS ебаться с "Nix" придётся с первой минуты. cast @Роман