Comments (5)
@WillemWybo : thanks for reporting this. I will look into it, could you help in define the semantics of the division operator? Should we be Python-like and have /
always represent floating point division, only (possibly) coercing the result to integer depending on the type of the variable we assign it to? I.e. (see especially x9):
parameters:
x1 real = 4 / 7 # expect 0.57..
x2 real = 4
x3 real = 7
x4 real = x2 / x3 # expect 0.57..
x5 integer = 4
x6 integer = 7
x7 integer = x5 / x6 # expect 0
x8 real = x5 / x6 # expect 0.57..
x9 real = x5 / x6 + x5 / x6 # expect 1 (C semantics would yield 0)
x10 integer = x2 / x3 + x2 / x3 # expect 1
from nestml.
We could also introduce the Python //
operator for integer (actually, "floor") division.
This means that a/b
would always be rendered in C++ as something like ((float)a)/((float)b)
.
But note that in Python, -3//2
equals -2 ("floor division"), whereas in C -3/2
equals -1 ("true" integer division). So we should be diligent about defining the semantics.
from nestml.
@clinssen you raise an interesting point. My functions were returning real
. It would make sense to make the division behaviour dependent upon the expected return type, as you propose.
Sympy seems to take the explicit approach, where sp.printing.ccode()
returns floor(a/b)
for a//b
and (float)a/(float)b
for a/b
. I guess if the variable is assigned to an integer it would be reasonable to expect the behaviour (int)floor(a/b)
or (int)((float)a/(float)b)
, the latter case being the true integer division.
Note that if the variable is part of some complex expression, i.e. exp(a/b + c)
, and then converted to an integer, I would still expect the behaviour (int)exp((float)a / (float)b + (float)c)
, but maybe this is personal taste.
from nestml.
Related Issues (20)
- Support vectorized input ports
- bug in neuron models with linear subthreshold dynamics HOT 1
- Unable to compile neuromodulated STDP synapse HOT 5
- Expression not assignable in dopamine modulated STDP synapse HOT 7
- Refactor ``print_nestml_type()`` methods on ``TypeSymbol``s
- Replace ``CoCoNoNestNameSpaceCollision`` with variable name rewriter HOT 1
- Replace occurrences of my fork ("clinssen") with upstream in docs
- Upgrade NEST version detection after NEST 3.4 release
- Add benchmarks to documentation HOT 1
- Ornstein-Uhlenbeck noise neuron fails to spike
- Remove outdated asserts from NEST templates HOT 2
- Separate NESTML model documentation
- Replace model links in Jupyter notebooks
- Introduce an ``import`` or ``include`` statement
- Add erf/erfc as predefined functions?
- Fix units in documentation example
- Threshold crossing based on derivative of membrane potential
- Synapse trace value can return 0 in edge case HOT 1
- Incorrect reference of spike input ports in the result of a numeric solver
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 nestml.