Hello. This is my update to my implementation of the Floating point numbers for #1. I have implemented 64 point bit floating point numbers based on the IEEE 754 standard by boxing the Flonum in the heap like in Racket. I have implemented Flonum operations of addition, subtraction, equality, less than or equal to, and type checking.
Idea:
The Flonum will be represented first by a pointer with its most right three bits flagged by 3 ones. In the address in the heap that this pointer points to, I have stored double 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 - 1023) + (1+m). The first 52 most-right bits will represent the mantissa m in binary form without the decimal point, the next 11 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.
The summary of the changes I made are:
General Changes
Changed mentions of "Float" to "Flonum"
The rounding feature was removed
types.rkt
imm -> bits, bits->imm`: Since a float is no longer an immediate, removes the case
flonum-> bits : Removes mentions of function related to rounding. Adjusted to fit the new mantissa size of 52.
integer-size : Removed
decimal_place : Removed
calc-exp: Changed the bias from 127 to 1023
bits->flonum: Adjusted to fit the new 64 bit format and removed the rounding
flonum->bits_helper : Adjusted to fit the new 64 bit format.
unload-bits-asm.rkt
bits->flonum: Adjusted to fit the new 64 bit format, removed the rounding , moved here since it is no longer an immediate
main.c
Same changes as bits->flonum
compile.rkt
Updated the literal and added case for fl+, fl-, fl=, fl<=, and flonum? and added more registers for scatch
fl+ was calculated by converting the smaller absolute float to the exponent and adding the mantissas after conversion if they were same sign and subtracting if they were not
fl- e1 e2 was simplified to fl e1 (- e2)
interp.rkt, parse.rkt
Updated the literal and added case for fl+, fl-, fl=, fl<=, and flonum?
interp-prims.rkt
Added racket's flonum libary
test-runner.rkt
Added tests to test the double floating point literals and the operators of fl+, fl-, fl=, fl<=, and flonum?
Possible things to add next:
For fl+ and fl-, there are slight inaccuracies like in Racket on some numbers. This may make me think if I need to re-add the significant digits rounder from the previous implementation. However, Racket also has slight inaccuracies on their float operations by the same significant digit, so this may not be needed.
Overflow errors
Update Read.rkt to read Floats. I am a bit confused by how to implement this.
Hello. This is my update to my implementation of the Floating point numbers for #1. I have implemented 64 point bit floating point numbers based on the IEEE 754 standard by boxing the Flonum in the heap like in Racket. I have implemented Flonum operations of addition, subtraction, equality, less than or equal to, and type checking.
Idea:
The Flonum will be represented first by a pointer with its most right three bits flagged by 3 ones. In the address in the heap that this pointer points to, I have stored double 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 - 1023) + (1+m). The first 52 most-right bits will represent the mantissa m in binary form without the decimal point, the next 11 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.
The summary of the changes I made are:
General Changes
types.rkt
imm -> bits
, bits->imm`: Since a float is no longer an immediate, removes the caseflonum-> bits
: Removes mentions of function related to rounding. Adjusted to fit the new mantissa size of 52.integer-size
: Removeddecimal_place
: Removedcalc-exp
: Changed the bias from 127 to 1023bits->flonum
: Adjusted to fit the new 64 bit format and removed the roundingbinary->decimal
,round_dec
,float-bits?
: Self explanatoryflonum->bits_helper
: Adjusted to fit the new 64 bit format.unload-bits-asm.rkt
bits->flonum
: Adjusted to fit the new 64 bit format, removed the rounding , moved here since it is no longer an immediatemain.c
bits->flonum
compile.rkt
fl+
,fl-
,fl=
,fl<=
, andflonum?
and added more registers for scatchfl- e1 e2 was simplified to fl e1 (- e2)
interp.rkt
,parse.rkt
Updated the literal and added case for
fl+
,fl-
,fl=
,fl<=
, andflonum?
interp-prims.rkt
test-runner.rkt
fl+
,fl-
,fl=
,fl<=
, andflonum?
Possible things to add next:
fl+
andfl-
, there are slight inaccuracies like in Racket on some numbers. This may make me think if I need to re-add the significant digits rounder from the previous implementation. However, Racket also has slight inaccuracies on their float operations by the same significant digit, so this may not be needed.Read.rkt
to read Floats. I am a bit confused by how to implement this.