> In the actual application my modulus will be unknown at compile time
I don't told you that the modulus should be a compile time constant, plain (1
<< x) with positive integer x should be enough for c compiler to see that
result is a power of two, so division can be replaced by masking.
> So i
> Division by 1^x should be something like and masking with (1^x - 1)...
In the actual application my modulus will be unknown at compile time, so I
can't apply any optimizations like that. But if I understand you, you're saying
that this might be an artifact of my using a modulus that is a power
> Is it the mod operator?
Seems to be very likely.
For
a1 = a1 % (((long long )1) << m2);
Run
it is easy to detect for the compiler that you are doing a modulo division by a
power of two, which is a plain bit masking operation. (Well, when signed
numbers are involve
Use `const` instead of `let` when you can, or just build with
--implicitStatic:on. Measurements on my computer:
./optimized_nim 1.01s user 0.00s system 99% cpu 1.012 total
./optimized_c 1.00s user 0.00s system 99% cpu 1.010 total
Run
I will be better to visit and consult with the site mentioned here
[https://errorcode0x.com/fix-epson-error-code-0xf4](https://errorcode0x.com/fix-epson-error-code-0xf4)/
to get the entire guidance regarding the computer algebra system module. It
will help you provide the required information ab
thanks.
> Can you show us the optimized Nim code too...
Sure. I left it out because the post was already long.
let
m2 = 10
m1 = 3*m2
b1 = 127
b2 = 256
mul = 102
a1 = 101
a2 = 7
a = (a1 shl m1) + a2
b = (b1 shl m1) + b2
ech
Oh -- the Nim compiler is 0.19.4. I originally encountered this some months ago
on an older Nim compiler, but decided to wait for a newer one before asking
about it. Then I just forgot until tonight.
I will be better to visit and consult with the site mentioned here
[https://errorcode0x.com/fix-epson-error-code-0xf4](https://errorcode0x.com/fix-epson-error-code-0xf4)/
to get the entire guidance regarding the computer algebra system module. It
will help you provide the required information ab
> Here's the un-optimized Nim code.
Can you show us the optimized Nim code too, so that we can see if we can
reproduce this large discrepancy?
Hello all
I was trying to optimize some modular arithmetic in a C++ program, and I had
the idea to try it in Nim first. The idea is to pack two (or more) small
integers into a 64-bit integer, perform a bunch of arithmetic, checking after
addition or multiplication whether one of them has grown
Done:
[https://github.com/nim-lang/Nim/issues/11228](https://github.com/nim-lang/Nim/issues/11228)
This belongs in the issue tracker:
[https://github.com/nim-lang/nim/issues](https://github.com/nim-lang/nim/issues)
Hi,
Consider the following code
# strange_option.nim
import options
let a: Option[int] = none(var int)
Run
When I compile with `nim c strange_option.nim` I get the following error
Hint: used config file '/usr/local/Cellar/nim/0.19.4/nim/con
What would be the equivalent of the following code in Nim (especially the
`rigidbody_t` structure and `physics_integrate` function)?
[https://pastebin.com/gXkBtHCE](https://pastebin.com/gXkBtHCE)
I want to create job functions running on (long-living) worker threads (#cores
- 1) that can act on
Thanks for all the replies.
I will have to take some time later to analyze the more idiomatic code above
and learn.
I understand my code may not appear to make sense. It's primary purpose is
simply to provide somewhat of a stress test of what I might commonly do in
various methods/functions. I
Very interesting explanation.
As regards Python floats, they are native floats (64 bits long in IEEE 754
format), not arbitrary precision floats. Only integers are in arbitrary
precision. So, I think that the rounding errors are also present in the Python
program.
Quick eureka before I sleep.
The bulk of processing is in the `sum` function for both Python and Nim, as
@Stefan_Salewski you should store the previous result because right now the
algorithm is doing an extra useless pass on `farray`, furthermore this relies
on the initialization of that empty
I just made an armv7a build on 0.19.6 for test purposes. Please let me know if
it works as expected. I plan making it a part of nightlies soon.
[https://bintray.com/genotrance/binaries/download_file?file_path=nim-0.19.6-linux_armv7a.tar.xz](https://bintray.com/genotrance/binaries/download_file?fi
Hey there,
This would be an idiomatic Nim translation of your program (and the result is
more similar to the Python one).
import os, strutils, times, math, parsecsv, streams
const CsvPath = "./build/EUR_USD_Week1.csv"
# Row: lTid,cDealable,CurrencyPair,RateDateTime,Rate
Unfortunately I can not really understand your code...
But it looks a bit strange for me.
for price in prices:
pcount += 1
farray[pcount] = ((price * price) * ((pcount+1) / prices.len))
pips += price
psum = farray.sum()
Run
In this loop you modi
Hello,
I have some code that I am trying to understand why it is slower than
Python/Numpy. I am not a C programmer and Nim is my first real attempt to learn
a systems level, statically compiled language. But to my understanding Nim
should approach C speeds to a certain extent. If what I present
Oh! Yes, `include` will give me the behavior I want. I have been working to
keep the modules separate, but I won't need to use any of them outside of my
learning project, so `include` isn't the end of the world.
I must say that I'm amazed that you worked on Table sorting for 3 years!
That works fine when I set the const from the command line when building:
$ nim c -r -d:is_it_for_algo_N=1 algo_1
$ nim c -r -d:is_it_for_algo_N=2 algo_2
Run
But it isn't enough to "set" the const in the algo-specific source file:
# In algo_.nim
Seems like you need to use `include` instead of `import`, along with all of its
implications.
The syntax of the sort command is sensitive to whitespace (or no WS)
For example, the command:
sesTab.sort(proc (x,y: (string,SesSeq)): int =
result = cmp(x[0], y[0]) )
Run
does not compile. However, putting a space after the comma in the type of x,y,
allows it to c
> reading through code on Github and other parts of the web? Simple convention
> — do not upload to public spaces your preprocessored code, dat simple
btw m$ with their .NET CLI compliant languages - tried to get similar approach,
but it is a m$, so they ended up with Mono monopoly, heh
So the alternative I mentioned doesn't work either?
const is_it_for_algo_N {.intdefine.} = 1
when is_it_for_algo_N == 1:
type Foo = object
val: int
elif is_it_for_algo_N == 2:
type Foo = object
val: string
Run
@moigagoo Thanks for this, I've been using Norm in developing a little
microblogging thing, and I like it's simplicity.
This is an interesting thread, and I didn't know syntax skins were such a
near-feature in Nim.
I'm very attracted to the idea - I think that syntax is actually very
important, but also a personal preference. There's not a lot to be gained by
arguing about it. I accept that some people like curl
**PRE** **PRO** **CES** **SORS**
We have awesome examples like Pug Stylus Coffeescript, but our lang is already
compiled, so it easiest things evar, just make preprocessor configuration _(in
yaml file would be nice)_ available for user custom schemes, which can be
defined global, or shipped wit
Thanks for both of your replies.
mratsim: I don't think that approach will give me quite what I want as my
import dependencies go the other way. Rather than defining the flag in a file
and deciding which file to import from there, I need to import a particular
file from each of two places and h
After reading this article
[https://en.wikipedia.org/wiki/Pseudocode](https://en.wikipedia.org/wiki/Pseudocode)
I'm starting to get involved _(slowly)_
yeah I noticed the length too, really nice look
> I’m surprised
but I'm not =) it sounds weird, that's why..
anyway I found nice thread
[htt
A quick update about the project.
Thanks to [alaviss](https://github.com/alaviss), SQLite backend supports
onUpdate and onDelete pragmas, foreign key handling now works (even with
multiple FKs).
getOne can retrieve a record not only by ID, but also by condition.
getMany and getOne procs now su
const is_it_for_algo_N {.intdefine.} = 1
when is_it_for_algo_N == 1:
import A
elif is_it_for_algo_N == 2:
import B
Run
And pass `nim c -d:is_it_for_algo_N=2 yourfile.nim`
Or just put the alternate type definition instead of the imports.
> Can I specify binary-specific defines for the nimble build process?
You can specify which kind of binary built with nimble task. See
[here](https://github.com/nim-lang/nimble#creating-packages)
You can also make a config file specific to your nim file so the name is
_yourfile.nim.cfg_ and put
37 matches
Mail list logo