Coder Social home page Coder Social logo

stdint.carp's Introduction

stdint

Update: This is now in core!

A wrapper around the types defined in stdint.h for Carp.

The numerical types are Int<8,16,32,64> and Uint<8,16,32,64>; the U means unsigned, the numbers denote the bit width of the type. This is taken straight out of the stdint header.

Interface

The interface is the same for all types. The following functions are supported:

; with T being any of the types in the library:

; tests for equality
(register = (λ [T T] Bool))
; tests whether the first parameter is larger than the second
(register > (λ [T T] Bool))
; tests whether the first parameter is smaller than the second
(register < (λ [T T] Bool)))

; adds two numbers
(register + (λ [T T] T)))
; subtracts two numbers
(register - (λ [T T] T)))
; multiplies two numbers
(register * (λ [T T] T)))
; divides two numbers
(register / (λ [T T] T)))

; shifts the first number left by a number of bytes specified by the second number
(register bit-shift-left (λ [T T] T)))
; shifts the first number right by a number of bytes specified by the second number
(register bit-shift-right (λ [T T] T)))
; performs a binary or on two numbers
(register bit-or (λ [T T] T)))
; performs a binary and on two numbers
(register bit-and (λ [T T] T)))
; performs a binary not on a number
(register bit-not (λ [T] T)))
; performs a binary xor on two numbers
(register bit-xor (λ [T T] T)))
; converts a number to a long (might lead to precision loss on the biggest types)
(register to-long (λ [T] Long)))
; converts a long to a number (not all possible numbers are supported by long)
(register from-long (λ [Long] T)))

; converts a number to a string (it will look like this: "(T <value>)")
(register str (λ [T] String)))

; converts a byte array into an array of T
; (if T is multiple bytes long, multiple bytes become one element)
; N.B.: it does not take care of endianness for you!
(register from-bytes (λ [&(Array Byte)] (Array T)))

I hope this helps in getting started! The tests in tests/ also showcase the interface.


Have fun!

stdint.carp's People

Contributors

hellerve avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.