{"action":"created","comment":{"url":"https://api.github.com/repos/Araq/Nim/pulls/comments/22841391","id":22841391,"diff_hunk":"@@ -0,0 +1,255 @@\n+#\n+#\n+#            Nim's Runtime Library\n+#        (c) Copyright 2015 Andreas Rumpf\n+#\n+#    See the file \"copying.txt\", included in this\n+#    distribution, for details about the copyright.\n+#\n+\n+\n+## This module implements rational numbers, consisting of a numerator `num` and\n+## a denominator `den`, both of type int. The denominator can not be 0.\n+\n+import math\n+\n+type Rational* = tuple[num, den: int]\n+  ## a rational number, consisting of a numerator and denominator\n+\n+proc toRational*(x: SomeInteger): Rational =\n+  ## Convert some integer `x` to a rational number.\n+  result.num = x\n+  result.den = 1\n+\n+proc toFloat*(x: Rational): float =\n+  ## Convert a rational number `x` to a float.\n+  x.num / x.den\n+\n+proc toInt*(x: Rational): int =\n+  ## Convert a rational number `x` to an int. Conversion rounds down if `x`\n+  ## does not contain an integer value.\n+  x.num div x.den","path":"lib/pure/rationals.nim","position":31,"original_position":31,"commit_id":"36de88726f3f230a4fce37400f15b883ff9c7c27","original_commit_id":"36de88726f3f230a4fce37400f15b883ff9c7c27","user":{"login":"ReneSac","id":6010063,"avatar_url":"https://avatars.githubusercontent.com/u/6010063?v=3","gravatar_id":"","url":"https://api.github.com/users/ReneSac","html_url":"https://github.com/ReneSac","followers_url":"https://api.github.com/users/ReneSac/followers","following_url":"https://api.github.com/users/ReneSac/following{/other_user}","gists_url":"https://api.github.com/users/ReneSac/gists{/gist_id}","starred_url":"https://api.github.com/users/ReneSac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReneSac/subscriptions","organizations_url":"https://api.github.com/users/ReneSac/orgs","repos_url":"https://api.github.com/users/ReneSac/repos","events_url":"https://api.github.com/users/ReneSac/events{/privacy}","received_events_url":"https://api.github.com/users/ReneSac/received_events","type":"User","site_admin":false},"body":"It rounds towards zero, not really \"down\".\r\n\r\n``` Nimrod\r\nassert( toInt( (5,3) ) == 1 )\r\nassert( toInt( (-5,3) ) == -1 )\r\n```","created_at":"2015-01-13T03:20:36Z","updated_at":"2015-01-13T03:20:36Z","html_url":"https://github.com/Araq/Nim/pull/1840#discussion_r22841391","pull_request_url":"https://api.github.com/repos/Araq/Nim/pulls/1840","_links":{"self":{"href":"https://api.github.com/repos/Araq/Nim/pulls/comments/22841391"},"html":{"href":"https://github.com/Araq/Nim/pull/1840#discussion_r22841391"},"pull_request":{"href":"https://api.github.com/repos/Araq/Nim/pulls/1840"}}},"pull_request":{"url":"https://api.github.com/repos/Araq/Nim/pulls/1840","id":26770816,"html_url":"https://github.com/Araq/Nim/pull/1840","diff_url":"https://github.com/Araq/Nim/pull/1840.diff","patch_url":"https://github.com/Araq/Nim/pull/1840.patch","issue_url":"https://api.github.com/repos/Araq/Nim/issues/1840","number":1840,"state":"open","locked":false,"title":"Rational numbers and a few additions to math and complex","user":{"login":"def-","id":2335377,"avatar_url":"https://avatars.githubusercontent.com/u/2335377?v=3","gravatar_id":"","url":"https://api.github.com/users/def-","html_url":"https://github.com/def-","followers_url":"https://api.github.com/users/def-/followers","following_url":"https://api.github.com/users/def-/following{/other_user}","gists_url":"https://api.github.com/users/def-/gists{/gist_id}","starred_url":"https://api.github.com/users/def-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/def-/subscriptions","organizations_url":"https://api.github.com/users/def-/orgs","repos_url":"https://api.github.com/users/def-/repos","events_url":"https://api.github.com/users/def-/events{/privacy}","received_events_url":"https://api.github.com/users/def-/received_events","type":"User","site_admin":false},"body":"Someone asked whether there is a rational numbers module in Nim, now there is.\r\n\r\nThe rest are additions that I commonly needed, so they may generally be useful.","created_at":"2015-01-02T20:55:56Z","updated_at":"2015-01-13T03:20:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"daff19742d71aa5a6b4cbe0f42ffae916d66eeeb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Araq/Nim/pulls/1840/commits","review_comments_url":"https://api.github.com/repos/Araq/Nim/pulls/1840/comments","review_comment_url":"https://api.github.com/repos/Araq/Nim/pulls/comments/{number}","comments_url":"https://api.github.com/repos/Araq/Nim/issues/1840/comments","statuses_url":"https://api.github.com/repos/Araq/Nim/statuses/36de88726f3f230a4fce37400f15b883ff9c7c27","head":{"label":"def-:extend-math","ref":"extend-math","sha":"36de88726f3f230a4fce37400f15b883ff9c7c27","user":{"login":"def-","id":2335377,"avatar_url":"https://avatars.githubusercontent.com/u/2335377?v=3","gravatar_id":"","url":"https://api.github.com/users/def-","html_url":"https://github.com/def-","followers_url":"https://api.github.com/users/def-/followers","following_url":"https://api.github.com/users/def-/following{/other_user}","gists_url":"https://api.github.com/users/def-/gists{/gist_id}","starred_url":"https://api.github.com/users/def-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/def-/subscriptions","organizations_url":"https://api.github.com/users/def-/orgs","repos_url":"https://api.github.com/users/def-/repos","events_url":"https://api.github.com/users/def-/events{/privacy}","received_events_url":"https://api.github.com/users/def-/received_events","type":"User","site_admin":false},"repo":{"id":21067069,"name":"Nim","full_name":"def-/Nim","owner":{"login":"def-","id":2335377,"avatar_url":"https://avatars.githubusercontent.com/u/2335377?v=3","gravatar_id":"","url":"https://api.github.com/users/def-","html_url":"https://github.com/def-","followers_url":"https://api.github.com/users/def-/followers","following_url":"https://api.github.com/users/def-/following{/other_user}","gists_url":"https://api.github.com/users/def-/gists{/gist_id}","starred_url":"https://api.github.com/users/def-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/def-/subscriptions","organizations_url":"https://api.github.com/users/def-/orgs","repos_url":"https://api.github.com/users/def-/repos","events_url":"https://api.github.com/users/def-/events{/privacy}","received_events_url":"https://api.github.com/users/def-/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/def-/Nim","description":"Nim is a compiled, garbage-collected systems programming language which has an excellent productivity/performance ratio. Nimrod's design focuses on efficiency, expressiveness, elegance (in the order of priority).","fork":true,"url":"https://api.github.com/repos/def-/Nim","forks_url":"https://api.github.com/repos/def-/Nim/forks","keys_url":"https://api.github.com/repos/def-/Nim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/def-/Nim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/def-/Nim/teams","hooks_url":"https://api.github.com/repos/def-/Nim/hooks","issue_events_url":"https://api.github.com/repos/def-/Nim/issues/events{/number}","events_url":"https://api.github.com/repos/def-/Nim/events","assignees_url":"https://api.github.com/repos/def-/Nim/assignees{/user}","branches_url":"https://api.github.com/repos/def-/Nim/branches{/branch}","tags_url":"https://api.github.com/repos/def-/Nim/tags","blobs_url":"https://api.github.com/repos/def-/Nim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/def-/Nim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/def-/Nim/git/refs{/sha}","trees_url":"https://api.github.com/repos/def-/Nim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/def-/Nim/statuses/{sha}","languages_url":"https://api.github.com/repos/def-/Nim/languages","stargazers_url":"https://api.github.com/repos/def-/Nim/stargazers","contributors_url":"https://api.github.com/repos/def-/Nim/contributors","subscribers_url":"https://api.github.com/repos/def-/Nim/subscribers","subscription_url":"https://api.github.com/repos/def-/Nim/subscription","commits_url":"https://api.github.com/repos/def-/Nim/commits{/sha}","git_commits_url":"https://api.github.com/repos/def-/Nim/git/commits{/sha}","comments_url":"https://api.github.com/repos/def-/Nim/comments{/number}","issue_comment_url":"https://api.github.com/repos/def-/Nim/issues/comments/{number}","contents_url":"https://api.github.com/repos/def-/Nim/contents/{+path}","compare_url":"https://api.github.com/repos/def-/Nim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/def-/Nim/merges","archive_url":"https://api.github.com/repos/def-/Nim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/def-/Nim/downloads","issues_url":"https://api.github.com/repos/def-/Nim/issues{/number}","pulls_url":"https://api.github.com/repos/def-/Nim/pulls{/number}","milestones_url":"https://api.github.com/repos/def-/Nim/milestones{/number}","notifications_url":"https://api.github.com/repos/def-/Nim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/def-/Nim/labels{/name}","releases_url":"https://api.github.com/repos/def-/Nim/releases{/id}","created_at":"2014-06-21T11:35:53Z","updated_at":"2015-01-12T22:05:26Z","pushed_at":"2015-01-13T00:33:32Z","git_url":"git://github.com/def-/Nim.git","ssh_url":"git@github.com:def-/Nim.git","clone_url":"https://github.com/def-/Nim.git","svn_url":"https://github.com/def-/Nim","homepage":"http://nim-lang.org/","size":34544,"stargazers_count":0,"watchers_count":0,"language":"Nimrod","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"devel"}},"base":{"label":"Araq:devel","ref":"devel","sha":"5023a9043858941d311c253fd1b62017080367be","user":{"login":"Araq","id":287816,"avatar_url":"https://avatars.githubusercontent.com/u/287816?v=3","gravatar_id":"","url":"https://api.github.com/users/Araq","html_url":"https://github.com/Araq","followers_url":"https://api.github.com/users/Araq/followers","following_url":"https://api.github.com/users/Araq/following{/other_user}","gists_url":"https://api.github.com/users/Araq/gists{/gist_id}","starred_url":"https://api.github.com/users/Araq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Araq/subscriptions","organizations_url":"https://api.github.com/users/Araq/orgs","repos_url":"https://api.github.com/users/Araq/repos","events_url":"https://api.github.com/users/Araq/events{/privacy}","received_events_url":"https://api.github.com/users/Araq/received_events","type":"User","site_admin":false},"repo":{"id":842037,"name":"Nim","full_name":"Araq/Nim","owner":{"login":"Araq","id":287816,"avatar_url":"https://avatars.githubusercontent.com/u/287816?v=3","gravatar_id":"","url":"https://api.github.com/users/Araq","html_url":"https://github.com/Araq","followers_url":"https://api.github.com/users/Araq/followers","following_url":"https://api.github.com/users/Araq/following{/other_user}","gists_url":"https://api.github.com/users/Araq/gists{/gist_id}","starred_url":"https://api.github.com/users/Araq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Araq/subscriptions","organizations_url":"https://api.github.com/users/Araq/orgs","repos_url":"https://api.github.com/users/Araq/repos","events_url":"https://api.github.com/users/Araq/events{/privacy}","received_events_url":"https://api.github.com/users/Araq/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Araq/Nim","description":"Nim (formerly known as \"Nimrod\") is a compiled, garbage-collected systems programming language which has an excellent productivity/performance ratio. Nim's design focuses on efficiency, expressiveness, elegance (in the order of priority).","fork":false,"url":"https://api.github.com/repos/Araq/Nim","forks_url":"https://api.github.com/repos/Araq/Nim/forks","keys_url":"https://api.github.com/repos/Araq/Nim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Araq/Nim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Araq/Nim/teams","hooks_url":"https://api.github.com/repos/Araq/Nim/hooks","issue_events_url":"https://api.github.com/repos/Araq/Nim/issues/events{/number}","events_url":"https://api.github.com/repos/Araq/Nim/events","assignees_url":"https://api.github.com/repos/Araq/Nim/assignees{/user}","branches_url":"https://api.github.com/repos/Araq/Nim/branches{/branch}","tags_url":"https://api.github.com/repos/Araq/Nim/tags","blobs_url":"https://api.github.com/repos/Araq/Nim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Araq/Nim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Araq/Nim/git/refs{/sha}","trees_url":"https://api.github.com/repos/Araq/Nim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Araq/Nim/statuses/{sha}","languages_url":"https://api.github.com/repos/Araq/Nim/languages","stargazers_url":"https://api.github.com/repos/Araq/Nim/stargazers","contributors_url":"https://api.github.com/repos/Araq/Nim/contributors","subscribers_url":"https://api.github.com/repos/Araq/Nim/subscribers","subscription_url":"https://api.github.com/repos/Araq/Nim/subscription","commits_url":"https://api.github.com/repos/Araq/Nim/commits{/sha}","git_commits_url":"https://api.github.com/repos/Araq/Nim/git/commits{/sha}","comments_url":"https://api.github.com/repos/Araq/Nim/comments{/number}","issue_comment_url":"https://api.github.com/repos/Araq/Nim/issues/comments/{number}","contents_url":"https://api.github.com/repos/Araq/Nim/contents/{+path}","compare_url":"https://api.github.com/repos/Araq/Nim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Araq/Nim/merges","archive_url":"https://api.github.com/repos/Araq/Nim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Araq/Nim/downloads","issues_url":"https://api.github.com/repos/Araq/Nim/issues{/number}","pulls_url":"https://api.github.com/repos/Araq/Nim/pulls{/number}","milestones_url":"https://api.github.com/repos/Araq/Nim/milestones{/number}","notifications_url":"https://api.github.com/repos/Araq/Nim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Araq/Nim/labels{/name}","releases_url":"https://api.github.com/repos/Araq/Nim/releases{/id}","created_at":"2010-08-16T20:38:58Z","updated_at":"2015-01-13T01:00:18Z","pushed_at":"2015-01-13T01:00:17Z","git_url":"git://github.com/Araq/Nim.git","ssh_url":"git@github.com:Araq/Nim.git","clone_url":"https://github.com/Araq/Nim.git","svn_url":"https://github.com/Araq/Nim","homepage":"http://nim-lang.org/","size":339384,"stargazers_count":1197,"watchers_count":1197,"language":"Nimrod","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":157,"mirror_url":null,"open_issues_count":398,"forks":157,"open_issues":398,"watchers":1197,"default_branch":"devel"}},"_links":{"self":{"href":"https://api.github.com/repos/Araq/Nim/pulls/1840"},"html":{"href":"https://github.com/Araq/Nim/pull/1840"},"issue":{"href":"https://api.github.com/repos/Araq/Nim/issues/1840"},"comments":{"href":"https://api.github.com/repos/Araq/Nim/issues/1840/comments"},"review_comments":{"href":"https://api.github.com/repos/Araq/Nim/pulls/1840/comments"},"review_comment":{"href":"https://api.github.com/repos/Araq/Nim/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/Araq/Nim/pulls/1840/commits"},"statuses":{"href":"https://api.github.com/repos/Araq/Nim/statuses/36de88726f3f230a4fce37400f15b883ff9c7c27"}}}}