-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Examples: Fix compiling issues and imports, closes #69 #73
Conversation
Sorry I have seen your comment after my PR, I am going to rebase my fix. |
see http://rosettacode.org/wiki/9_billion_names_of_God_the_integer#Nim that version is supposed to be slow and as such should not be kept running. version 2 is the fast one. |
I have :
|
@konsumlamm, your review please :) |
I would adapt rc_leftfactorials.nim it to something like this (playground): iterator square: int =
var i = 0
while true:
yield i*i
inc i
var i = 0
for n in square():
if i <= 10:
echo i, ": ", n
elif i <= 110 and i mod 10 == 0:
echo i, ": ", n
elif i >= 1000 and i <= 10_000 and i mod 1000 == 0:
echo i, ": ", n
elif i > 10_000:
break
inc i |
in for x in [23, 123, 1234, 12345]: to # for 12345 this implementation is too slow, for a faster implementation see rc_godtheinteger2.nim
for x in [23, 123, 1234]: |
Thanks a lot @pietroppeter, the two new commits follow up from your ideas. |
@@ -20,16 +29,16 @@ proc extractDigit(): int32 = | |||
if tmp2 >= den: | |||
return -1 | |||
|
|||
result = int32(tmp1.limbs[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example can not be rewritten as long as we have not defined a way to convert a BigInt into an int, see issue #72. Type cast does not do the same thing, it interprets the BigInt as an int ! So the first limb is understood as the 2’s complement representation of another number. Thanks @konsumlamm for the explanation. Same for examples/rc_pidigits.nim
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, we should also test these examples in the CI (I didn't even know they existed until recently).
Co-authored-by: konsumlamm <[email protected]>
This will make the object of another PR This reverts commit 4aca9d8.
All examples compile, only pidigits examples does not work but this may be fixed with PR #74. |
Pidigits examples now compile, but in case toSignedInt change name, we will have to modify slightly the examples again. |
@konsumlamm or @pietroppeter may I ask for a review on this PR ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the link in examples/rc_godtheinteger.nim
to https://rosettacode.org/wiki/9_billion_names_of_God_the_integer
and change all links to https?
examples/pidigits.nim
Outdated
@@ -1,10 +1,19 @@ | |||
# Translation of http://benchmarksgame.alioth.debian.org/u32/program.php?test=pidigits&lang=go&id=4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link is broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, isn't this example essentially a duplicate of rc_pidigits.nim
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pidigits.nim file is the interactive version of rc_pidigits.nim
The pidigits.nim asks the user for the number of digits of pi he wants, whereas rc_pidigits.nim prints indefinitely new digits of pi.
I can remove rc_pidigits.nim if you want. Especially knowing that the code (now outdated) is published on the website.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really care which one we keep.
@narimiran May I ask to merge this PR ? |
Fix compilation errors for many examples.
Change
import bigints
toimport ../src/bigints
to ensure examples are tested with the development version and not the stable version. This might be changed back when a stable version is going to be released.Changed imports from standard library to differentiate them from external libraries :
import strutils, math
becomeimport std/[strutils, math]
As there is no implicit type conversion for integers to BigInt anymore, operations between a BigInt and an Integer now become operations between BigInt and integer explicitly converted to BigInt.
Now three examples do not work :