Comments (3)
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.
I'll have to look into this (you can also write numbers directly in scientific notation, something like "1.23e35")
from kos.
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)
- Stack misalignment bug HOT 3
- Scope seems to be considered differently 'on board' and 'in Archive' HOT 4
- Resizing terminal repeatedly causes a memory leak [BUG]
- Feature Request: "On Script Error" setting on controller part
- Setting part module field value has no effect for some mods
- docs:"make latexpdf" generates only 19 pages (and they are almost empty) HOT 1
- Some system monospace fonts are not recognized by kOS terminal HOT 2
- Redundancy in compiled form of UNTIL
- Changing the active vessel using `kuniverse` from IVA mode will break the internal camera until the next scene change HOT 4
- KOSVesselModule can populate allInstances dictionary with an ID of 0
- KOSVesselModules has a memory leak problem
- Terminal breaks when something is typed that extends beyond the terminal window
- ship:control:mainthrottle doesn't work unless some other raw control is set [BUG]
- Global vars 'undefined' in local scope after running any program. HOT 6
- Undefined var when checking if the same var is defined HOT 2
- make sure kosnametag doesn't spend time updating
- Get create-release up and running
- Get docs building on github actions
- CI: changelog updating
- Function gets called when checking if a var with same name is defined HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kos.