Tuesday, 8 July 2014

64 Bit Integer Arithmetic For Red/System

Red/System is the low-level dialect of the Red Programming Language. It is a compiled language, its datatypes and variables work like C, whereas its syntax is very similar to Red. The Red runtime is written in Red/System and the Red compiler outputs Red/System code (which is then compiled to native code).

The current version of Red/System has been written to meet those two needs and to do little more. Once Version 1.0 of Red is complete, the Red/System compiler will be re-written in Red (the current one is written in Rebol).

Using Red/System, it is very easy to write interfaces to external libraries written in C. There is a slight catch however, integers in Red/System are 32 bit integers and some libraries return 64 bit integers.

I've written a simple 64 bit integer arithmetic library for Red/System to make it easier to deal with such libraries. I expect that Red/System 2 will include built-in support for 64 bit integers so the library reflects its temporary nature.

The main functions are add, subtract, multiply, and divide. I used easy algorithms such as long multiplication and division.  There are a number of supporting functions and macros too.

You can find the library on Github.

No comments: