plum-umd / the-838e-compiler

Compiler for CMSC 838E
2 stars 0 forks source link

Floating point #31

Closed WChung43 closed 3 years ago

WChung43 commented 3 years ago

Hello. This is my implementation of the Floating point numbers for #1. I have implemented 32 point bit floating point numbers based on the IEEE 754 standard.

Idea:

I have stored single precision floating point numbers in the 64-bit integer by storing the mantissa m, the exponent e, and the sign s where the floating point number = (-1)^s * 2^(e - 127) + (1+m). The 64-bit integer will have the first 3 most-right bits and the next 5 most-right bits be 1 in order to represent its flag of being a float. Then, the next 23 most-right bits will represent the mantissa m in binary form without the decimal point, the next 8 most-right bits will represent the exponent e, and the next bit will represent the sign s that will be 0 for positive or 1 for negative. Then, the next 3 bits will represent how decimal places d to round the floating point up to when the bits get converted to a float and printed.

Currently, the number is only accurate up to 7 significant figures and therefore will only round up to 0 or n many decimals where n = 7 - significant figures.

The summary of the changes I made are:

types.rkt

main.c

Makefile, a86/interp.rkt

ast.rkt, compile.rkt, interp.rkt, parse.rkt, types.h

test-runner.rkt

Possible things to add next:

Note about Tests: