in reply to Re^2: porting C code to Perl -- solved
in thread porting C code to Perl
I spotted the type casting of int but I have not thought it constrained all the operations too
In C, when you say int q;, that variable is fixed to, depending on how your compiler defines it, a 32 (or 16 or 64) bit signed integer value, no more, no less - simplifying a bit, no matter what you try to assign to it, it will be cast back to an int.
Now I ported to a more perlish versions, but speaking frankly, I'm quite struggling with it's efficiency.
Since functionally the two programs are practically identical, that'll simply be the difference between a complied and interpreted language. I don't have much time for optimization right now, but you might try to compare the performance of the program with and without use integer; - I'm not sure if it'll make a significant difference but it's worth a try.
In reality I'm working blindly not have well understood wht the code do.
A bit of googling on the algorithm brings me to this page, while it's a bit difficult to read visually, it seems to give an example-based explanation of the "spigot algorithm" that this appears to be an implementation of.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: porting C code to Perl -- use integer bench
by Discipulus (Canon) on Oct 24, 2017 at 07:12 UTC | |
by haukex (Archbishop) on Oct 24, 2017 at 18:22 UTC |