1. Assembler / Говнокод #25239

    +2

    1. 1
    2. 2
    3. 3
    https://www.researchgate.net/publication/325358150_cQASM_v10_Towards_a_Common_Quantum_Assembly_Language
    
    cQASM v1.0: Towards a Common Quantum Assembly Language

    The quantum assembly language (QASM) is a popular intermediate representation used in many quantum compilation and simulation tools to describe quantum circuits. Currently, multiple different dialects of QASM are used in different quantum computing tools. This makes the interaction between those tools tedious and time-consuming due to the need for translators between theses different syntaxes. Beside requiring a multitude of translators, the translation process exposes the constant risk of loosing information due to the potential incompatibilities between the different dialects. Moreover, several tools introduce details of specific target hardware or qubit technologies within the QASM syntax and prevent porting the code to other hardwares. In this paper, we propose a common QASM syntax definition, named cQASM, which aims to abstract away qubit technology details and guarantee the interoperability between all the quantum compilation and simulation tools supporting this standard. Our vision is to enable an extensive quantum computing toolbox shared by all the quantum computing community.

    Вот это я понимаю, а то вон там мелкософт какие-то говношарпы придумывает очередные:

    https://docs.microsoft.com/en-us/quantum/language/?view=qsharp-preview


    Нахер ваши шарпы с вашим сраным дуднетом и прочей такой хуйней, даешь Assembler.

    j123123, 28 Декабря 2018

    Комментарии (187)
  2. PHP / Говнокод #25237

    +1

    1. 1
    $today = new \DateTime('@'.strtotime(date("y-m-d", time())));

    Today

    makaka16, 27 Декабря 2018

    Комментарии (1)
  3. 1C / Говнокод #25236

    0

    1. 1
    Сумма = Цел(Окр(Сумма * 1000, 0, 1)) / 1000;

    Или я мандаринов переел, или от этого портал должен открыться

    valchara, 27 Декабря 2018

    Комментарии (42)
  4. PHP / Говнокод #25234

    +2

    1. 1
    2. 2
    Дайте инвайт этому господину
    https://habr.com/sandbox/125898/

    LinuxGovno, 27 Декабря 2018

    Комментарии (5)
  5. Си / Говнокод #25230

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    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;

    Того рот ебал, пыхамакаки в деле

    dicklover, 26 Декабря 2018

    Комментарии (15)
  6. Си / Говнокод #25229

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    #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++ их по-прежнему нет.

    j123123, 26 Декабря 2018

    Комментарии (144)
  7. Assembler / Говнокод #25228

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    /*
    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
    Почему компиляторы до сих пор такое говно

    j123123, 26 Декабря 2018

    Комментарии (94)
  8. JavaScript / Говнокод #25227

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    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

    phpMASTER666, 26 Декабря 2018

    Комментарии (2)
  9. Си / Говнокод #25226

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    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.
    Ветвление легко имитируеься массивом функий, цикол —– рукурсией. Получилось даже короче и понятнее чем обычный код.

    Morgoth, 26 Декабря 2018

    Комментарии (94)
  10. C++ / Говнокод #25225

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    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;
    }

    Преобразование строки в число

    patzantre, 26 Декабря 2018

    Комментарии (6)