Code Monkey home page Code Monkey logo

Comments (1)

mntmn avatar mntmn commented on July 29, 2024

Thanks for your feedback, mathias. I'm planning to include double-precision 64-bit IEEE 754 floating point numbers. This opens many questions of how and when to convert between fp and integers (probably always explicitly).

To implement a new type like TAG_FLOAT, you need to:

  • add a TAG_FLOAT constant in minilisp.h (they are currently power-of-two-ints, but this can be changed except for TAG_MARK which has to be a bit)
  • add alloc_float(double f) function in alloc.h / alloc.c (you can copy stuff from alloc_int)
  • add a state PST_FLOAT in reader.h and switch from PST_NUM or PST_ATOM to PST_FLOAT in reader.c when a '.' is encountered
  • implement PST_FLOAT parser in reader.c (which calls alloc_float with the parsed number)
  • implement PST_FLOAT printing in writer.c
  • probably implement load_float in compiler_new.c analog to load_int (maybe triggering a refactor to make load_int/_cell/_float more compact). alternatively first always use boxed floats to make things simpler. then you would only need to expand load_int to coerce a float cell to an integer.
  • introduce BUILTIN_FADD / _FSUB / _FMUL / FDIV cases in compiler_new.c and jit*.c and register those constants in compiler_new.h enum builtin_t

I think that should be about it! :)

About division by zero: I'll look into this, it is platform specific, and there are 4 more exceptions on floating point hardware.

Cheers
Lukas

from interim.

Related Issues (16)

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.