Giter Site home page Giter Site logo

Comments (3)

Dunbaratu avatar Dunbaratu commented on August 13, 2024

A similar problem happens with multiplication of big integers:

set x to 100000000.  // small enough to fit in an int32
print x.
100000000.
set y to 500000000. // also small enough to fit in an int32
print y.
500000000.
print x * y.  // too big for an int32
784662528.

I'm not sure what a good solution to the problem should be. On the one hand programmers have dealt with this for years and know the difference between integers. long integers, floats and doubles and so on, And the difference between typing 10 and typing 10.0 in your code. But on the other hand kosscript hides type information from the script programmer, trying to mask all that off, making places where it leaks through like this stick out. The kosscript programmer can't say something like "print (Double)x * y" to manually force the type promotion..

There appears to be code to check the magnitude of literals in the code so you can say:
set x to 10000.
and end up with an integer, but if you say
set x to 10000000000000.
you end up with a Double.
Can a similar check be done on all integer operations? If the integer math overflowed, then try it again promoted to doubles?

from kos.

marianoapp avatar marianoapp commented on August 13, 2024

I'll have to look into this (you can also write numbers directly in scientific notation, something like "1.23e35")

from kos.

Dunbaratu avatar Dunbaratu commented on August 13, 2024

Yeah I can't think of an obvious answer to the problem. I'd be curious to see what you come up with. Making everything a Double is easy, but could cause other potential problems when people expect variables to behave like integers in things like loop indeces.

from kos.

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.