Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HeXenCore/ed44c605cd66a95278bde0d1170c0476 to your computer and use it in GitHub Desktop.

Select an option

Save HeXenCore/ed44c605cd66a95278bde0d1170c0476 to your computer and use it in GitHub Desktop.

Revisions

  1. @ricrogz ricrogz renamed this gist Oct 14, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @ricrogz ricrogz revised this gist Oct 14, 2017. No changes.
  3. @ricrogz ricrogz renamed this gist Oct 14, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @ricrogz ricrogz created this gist Oct 14, 2017.
    10 changes: 10 additions & 0 deletions foo.pyx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    cdef extern from "header_int128.h":
    # Basically, we cheat cython to think we will use unsigned long long,
    # which is a 64 bit int ...
    ctypedef unsigned long long int128

    print "hello world"

    cpdef int foo():
    cdef int128 foo = 4
    return 32
    8 changes: 8 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Taken from https://stackoverflow.com/questions/27582001/how-to-use-128-bit-integers-in-cython

    Basically, we make cython believe we will use 64 bit int to generate the .c file,
    but by using a C header we will, in fact, define a 128 bit int (the definition
    in the .h file does not match what we put into the pyx file).

    Once Cython has generated the .c file, we can compile it with GCC without further trouble,
    as GCC does support 128 bit ints
    3 changes: 3 additions & 0 deletions header_int128.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    // ... but in the header, we give another definition,
    // the one for a 128 bit int.
    typedef __int128_t int128;