Giter Club home page Giter Club logo

Comments (4)

elucent avatar elucent commented on May 27, 2024

Closing this, since these are included in the rewritten v1.0 branch! Float is the 32-bit floating-point type, and Double is the 64-bit one.

from basil.

dumblob avatar dumblob commented on May 27, 2024

a) Are float literals safe in runtime (i.e. checked in compile-time)?

b) Would it be possible to use the compile-time functionality to import automatically the mpdecimal library on demand and treat all float literals as decimal float literals (instead of the default binary float literals)?

from basil.

elucent avatar elucent commented on May 27, 2024

I wouldn't consider this unsafe, it's kind of just an inherent feature of floating-point...which is fine, I think. My thoughts on this are that as long as Basil is pretty clear about where it's using floating-point, it should be pretty clear where one uses it as a trade-off between perfect accuracy and performance (no floating-point alternative is anywhere near as fast on modern hardware, and esp. 64-bit floats have pretty low error margins IMO). In general, I'm leaning more towards performance over the kinds of "strict correctness" features we see in some other languages.

Not sure how I feel about opaquely changing the default behavior of the compiler, esp. with regards to constants, but it should be possible to write a pleasant interface to any decimal library you want. It's a little outdated but I've actually already implemented a rational approximation in Basil in https://github.com/basilTeam/basil/blob/v1.0/example/rational.bl - with a few more language features (like user-defined implicit conversions, so you can somewhat transparently write def x : Rational = 10 equivalently to def x = Rational 10 or something) it should be fairly smooth.

from basil.

dumblob avatar dumblob commented on May 27, 2024

I wouldn't consider this unsafe, it's kind of just an inherent feature of floating-point...which is fine, I think. My thoughts on this are that as long as Basil is pretty clear about where it's using floating-point, it should be pretty clear where one uses it as a trade-off between perfect accuracy and performance (no floating-point alternative is anywhere near as fast on modern hardware, and esp. 64-bit floats have pretty low error margins IMO).

I was myself shocked that mpdecimal (an arbitrary precision decimal float) is about 2-3x slower than native 64bit binary floats on average. Only in games (or any kind of visualization) and scientific libs (or anything having floats in a tight loop) I'd use a mixture of binary & decimal floats for performance reasons. But in any other scenario I can think of, the advantages of decimal floats (especially mpdecimal) by far outweight the IMHO totally acceptable slowness so I'd use only decimal floats.

Do you have different observations?

In general, I'm leaning more towards performance over the kinds of "strict correctness" features we see in some other languages.

In general I understand and lean also to performance. On the other hand, I'd like to have a mechanism to ensure the higher safety. So I'd really like to be able to tell Basil to treat float literals as decimals.

Not sure how I feel about opaquely changing the default behavior of the compiler, esp. with regards to constants, but it should be possible to write a pleasant interface to any decimal library you want. It's a little outdated but I've actually already implemented a rational approximation in Basil in https://github.com/basilTeam/basil/blob/v1.0/example/rational.bl - with a few more language features (like user-defined implicit conversions, so you can somewhat transparently write def x : Rational = 10 equivalently to def x = Rational 10 or something) it should be fairly smooth.

Hm, this might work if the float number will be treated untyped until the type of LHS is fully resolved. Because otherwise one would lose precision when converting binary float to a decimal float.

Could you clarify whether Basil treats float literals as untyped floats (i.e. without any loss of precision)?

from basil.

Related Issues (20)

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.