{"action":"created","comment":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/39399954","id":39399954,"diff_hunk":"@@ -443,6 +425,219 @@ var builtins = map[string][]builtin{\n \t\"max\": aggregateImpls(boolType, intType, floatType, stringType),\n \t\"min\": aggregateImpls(boolType, intType, floatType, stringType),\n \t\"sum\": aggregateImpls(intType, floatType),\n+\n+\t// Math functions\n+\n+\t\"abs\": {\n+\t\tbuiltin{\n+\t\t\treturnType: DummyFloat,\n+\t\t\ttypes:      typeList{floatType},\n+\t\t\tfn: func(args DTuple) (Datum, error) {\n+\t\t\t\treturn DFloat(math.Abs(float64(args[0].(DFloat)))), nil\n+\t\t\t},\n+\t\t},\n+\t\tbuiltin{\n+\t\t\treturnType: DummyInt,\n+\t\t\ttypes:      typeList{intType},\n+\t\t\tfn: func(args DTuple) (Datum, error) {\n+\t\t\t\tx := args[0].(DInt)\n+\t\t\t\tswitch {\n+\t\t\t\tcase x == math.MinInt64:\n+\t\t\t\t\treturn DNull, errAbsOfMinInt64\n+\t\t\t\tcase x < 0:\n+\t\t\t\t\treturn -x, nil\n+\t\t\t\t}\n+\t\t\t\treturn x, nil\n+\t\t\t},\n+\t\t},\n+\t},\n+\n+\t\"acos\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Acos(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"asin\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Asin(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"atan\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Atan(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"atan2\": {\n+\t\tfloatBuiltin2(func(x, y float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Atan2(x, y)), nil\n+\t\t}),\n+\t},\n+\n+\t\"ceil\":    {ceilImpl},\n+\t\"ceiling\": {ceilImpl},\n+\n+\t\"cos\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Cos(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"degrees\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(180.0 * x / math.Pi), nil\n+\t\t}),\n+\t},\n+\n+\t\"div\": {\n+\t\tfloatBuiltin2(func(x, y float64) (Datum, error) {\n+\t\t\treturn DFloat(x / y), nil\n+\t\t}),\n+\t},\n+\n+\t\"exp\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Exp(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"floor\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Floor(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"ln\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Log(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"log\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Log10(x)), nil\n+\t\t}),\n+\t},\n+\n+\t\"mod\": {\n+\t\tfloatBuiltin2(func(x, y float64) (Datum, error) {\n+\t\t\treturn DFloat(math.Mod(x, y)), nil\n+\t\t}),\n+\t\tbuiltin{\n+\t\t\treturnType: DummyInt,\n+\t\t\ttypes:      typeList{intType, intType},\n+\t\t\tfn: func(args DTuple) (Datum, error) {\n+\t\t\t\ty := args[1].(DInt)\n+\t\t\t\tif y == 0 {\n+\t\t\t\t\treturn DNull, errDivisionByZero\n+\t\t\t\t}\n+\t\t\t\tx := args[0].(DInt)\n+\t\t\t\treturn DInt(x - (x/y)*y), nil\n+\t\t\t},\n+\t\t},\n+\t},\n+\n+\t\"pi\": {\n+\t\tbuiltin{\n+\t\t\treturnType: DummyFloat,\n+\t\t\ttypes:      typeList{},\n+\t\t\tfn: func(args DTuple) (Datum, error) {\n+\t\t\t\treturn DFloat(math.Pi), nil\n+\t\t\t},\n+\t\t},\n+\t},\n+\n+\t\"pow\":   {powImpl},\n+\t\"power\": {powImpl},\n+\n+\t\"radians\": {\n+\t\tfloatBuiltin1(func(x float64) (Datum, error) {\n+\t\t\treturn DFloat(x * math.Pi / 180.0), nil\n+\t\t}),\n+\t},\n+\n+\t// TODO(thschroeter): should we support round for our floatType?","path":"sql/parser/builtins.go","position":196,"original_position":196,"commit_id":"2c0555d4f3c7db651fd30d9c8ed450947bb9095f","original_commit_id":"2c0555d4f3c7db651fd30d9c8ed450947bb9095f","user":{"login":"petermattis","id":6201335,"avatar_url":"https://avatars.githubusercontent.com/u/6201335?v=3","gravatar_id":"","url":"https://api.github.com/users/petermattis","html_url":"https://github.com/petermattis","followers_url":"https://api.github.com/users/petermattis/followers","following_url":"https://api.github.com/users/petermattis/following{/other_user}","gists_url":"https://api.github.com/users/petermattis/gists{/gist_id}","starred_url":"https://api.github.com/users/petermattis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/petermattis/subscriptions","organizations_url":"https://api.github.com/users/petermattis/orgs","repos_url":"https://api.github.com/users/petermattis/repos","events_url":"https://api.github.com/users/petermattis/events{/privacy}","received_events_url":"https://api.github.com/users/petermattis/received_events","type":"User","site_admin":false},"body":"MySQL supports `round` for `int`, `float` and `numeric`. I think it makes sense to support for `int` and `float`, but I'm not thrilled with the implementation below going through `Sprintf` and `ParseFloat`. ","created_at":"2015-09-14T14:29:19Z","updated_at":"2015-09-14T14:29:19Z","html_url":"https://github.com/cockroachdb/cockroach/pull/2484#discussion_r39399954","pull_request_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484","_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments/39399954"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2484#discussion_r39399954"},"pull_request":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484"}}},"pull_request":{"url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484","id":44826731,"html_url":"https://github.com/cockroachdb/cockroach/pull/2484","diff_url":"https://github.com/cockroachdb/cockroach/pull/2484.diff","patch_url":"https://github.com/cockroachdb/cockroach/pull/2484.patch","issue_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2484","number":2484,"state":"open","locked":false,"title":"[DO NOT MERGE] Add math builtins.","user":{"login":"thschroeter","id":40804,"avatar_url":"https://avatars.githubusercontent.com/u/40804?v=3","gravatar_id":"","url":"https://api.github.com/users/thschroeter","html_url":"https://github.com/thschroeter","followers_url":"https://api.github.com/users/thschroeter/followers","following_url":"https://api.github.com/users/thschroeter/following{/other_user}","gists_url":"https://api.github.com/users/thschroeter/gists{/gist_id}","starred_url":"https://api.github.com/users/thschroeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thschroeter/subscriptions","organizations_url":"https://api.github.com/users/thschroeter/orgs","repos_url":"https://api.github.com/users/thschroeter/repos","events_url":"https://api.github.com/users/thschroeter/events{/privacy}","received_events_url":"https://api.github.com/users/thschroeter/received_events","type":"User","site_admin":false},"body":"Work in progress towards support for more math builtins. So far, I've implemented `abs`, `pi` and `sin`. I hope this is what you have in mind. Will add more functions tomorrow. Probably with a `floatBuiltin1` helper.\r\n\r\n#2042","created_at":"2015-09-11T20:42:07Z","updated_at":"2015-09-14T14:29:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"af1bd8e9071b591cde08775480d6b4ff0d2d6fb7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484/commits","review_comments_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484/comments","review_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/2484/comments","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/2c0555d4f3c7db651fd30d9c8ed450947bb9095f","head":{"label":"thschroeter:math-builtins","ref":"math-builtins","sha":"2c0555d4f3c7db651fd30d9c8ed450947bb9095f","user":{"login":"thschroeter","id":40804,"avatar_url":"https://avatars.githubusercontent.com/u/40804?v=3","gravatar_id":"","url":"https://api.github.com/users/thschroeter","html_url":"https://github.com/thschroeter","followers_url":"https://api.github.com/users/thschroeter/followers","following_url":"https://api.github.com/users/thschroeter/following{/other_user}","gists_url":"https://api.github.com/users/thschroeter/gists{/gist_id}","starred_url":"https://api.github.com/users/thschroeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thschroeter/subscriptions","organizations_url":"https://api.github.com/users/thschroeter/orgs","repos_url":"https://api.github.com/users/thschroeter/repos","events_url":"https://api.github.com/users/thschroeter/events{/privacy}","received_events_url":"https://api.github.com/users/thschroeter/received_events","type":"User","site_admin":false},"repo":{"id":29617637,"name":"cockroach","full_name":"thschroeter/cockroach","owner":{"login":"thschroeter","id":40804,"avatar_url":"https://avatars.githubusercontent.com/u/40804?v=3","gravatar_id":"","url":"https://api.github.com/users/thschroeter","html_url":"https://github.com/thschroeter","followers_url":"https://api.github.com/users/thschroeter/followers","following_url":"https://api.github.com/users/thschroeter/following{/other_user}","gists_url":"https://api.github.com/users/thschroeter/gists{/gist_id}","starred_url":"https://api.github.com/users/thschroeter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thschroeter/subscriptions","organizations_url":"https://api.github.com/users/thschroeter/orgs","repos_url":"https://api.github.com/users/thschroeter/repos","events_url":"https://api.github.com/users/thschroeter/events{/privacy}","received_events_url":"https://api.github.com/users/thschroeter/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/thschroeter/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":true,"url":"https://api.github.com/repos/thschroeter/cockroach","forks_url":"https://api.github.com/repos/thschroeter/cockroach/forks","keys_url":"https://api.github.com/repos/thschroeter/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thschroeter/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thschroeter/cockroach/teams","hooks_url":"https://api.github.com/repos/thschroeter/cockroach/hooks","issue_events_url":"https://api.github.com/repos/thschroeter/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/thschroeter/cockroach/events","assignees_url":"https://api.github.com/repos/thschroeter/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/thschroeter/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/thschroeter/cockroach/tags","blobs_url":"https://api.github.com/repos/thschroeter/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thschroeter/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thschroeter/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/thschroeter/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thschroeter/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/thschroeter/cockroach/languages","stargazers_url":"https://api.github.com/repos/thschroeter/cockroach/stargazers","contributors_url":"https://api.github.com/repos/thschroeter/cockroach/contributors","subscribers_url":"https://api.github.com/repos/thschroeter/cockroach/subscribers","subscription_url":"https://api.github.com/repos/thschroeter/cockroach/subscription","commits_url":"https://api.github.com/repos/thschroeter/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/thschroeter/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/thschroeter/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/thschroeter/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/thschroeter/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/thschroeter/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thschroeter/cockroach/merges","archive_url":"https://api.github.com/repos/thschroeter/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thschroeter/cockroach/downloads","issues_url":"https://api.github.com/repos/thschroeter/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/thschroeter/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/thschroeter/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/thschroeter/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thschroeter/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/thschroeter/cockroach/releases{/id}","created_at":"2015-01-21T21:38:27Z","updated_at":"2015-01-21T21:38:29Z","pushed_at":"2015-09-14T10:07:21Z","git_url":"git://github.com/thschroeter/cockroach.git","ssh_url":"git@github.com:thschroeter/cockroach.git","clone_url":"https://github.com/thschroeter/cockroach.git","svn_url":"https://github.com/thschroeter/cockroach","homepage":null,"size":30860,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"master"}},"base":{"label":"cockroachdb:master","ref":"master","sha":"c39c555570ef6fe3834cd2a5f7a67e368e3f76a8","user":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"repo":{"id":16563587,"name":"cockroach","full_name":"cockroachdb/cockroach","owner":{"login":"cockroachdb","id":6748139,"avatar_url":"https://avatars.githubusercontent.com/u/6748139?v=3","gravatar_id":"","url":"https://api.github.com/users/cockroachdb","html_url":"https://github.com/cockroachdb","followers_url":"https://api.github.com/users/cockroachdb/followers","following_url":"https://api.github.com/users/cockroachdb/following{/other_user}","gists_url":"https://api.github.com/users/cockroachdb/gists{/gist_id}","starred_url":"https://api.github.com/users/cockroachdb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cockroachdb/subscriptions","organizations_url":"https://api.github.com/users/cockroachdb/orgs","repos_url":"https://api.github.com/users/cockroachdb/repos","events_url":"https://api.github.com/users/cockroachdb/events{/privacy}","received_events_url":"https://api.github.com/users/cockroachdb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cockroachdb/cockroach","description":"A Scalable, Geo-Replicated, Transactional Datastore","fork":false,"url":"https://api.github.com/repos/cockroachdb/cockroach","forks_url":"https://api.github.com/repos/cockroachdb/cockroach/forks","keys_url":"https://api.github.com/repos/cockroachdb/cockroach/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cockroachdb/cockroach/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cockroachdb/cockroach/teams","hooks_url":"https://api.github.com/repos/cockroachdb/cockroach/hooks","issue_events_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/events{/number}","events_url":"https://api.github.com/repos/cockroachdb/cockroach/events","assignees_url":"https://api.github.com/repos/cockroachdb/cockroach/assignees{/user}","branches_url":"https://api.github.com/repos/cockroachdb/cockroach/branches{/branch}","tags_url":"https://api.github.com/repos/cockroachdb/cockroach/tags","blobs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cockroachdb/cockroach/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cockroachdb/cockroach/git/refs{/sha}","trees_url":"https://api.github.com/repos/cockroachdb/cockroach/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cockroachdb/cockroach/statuses/{sha}","languages_url":"https://api.github.com/repos/cockroachdb/cockroach/languages","stargazers_url":"https://api.github.com/repos/cockroachdb/cockroach/stargazers","contributors_url":"https://api.github.com/repos/cockroachdb/cockroach/contributors","subscribers_url":"https://api.github.com/repos/cockroachdb/cockroach/subscribers","subscription_url":"https://api.github.com/repos/cockroachdb/cockroach/subscription","commits_url":"https://api.github.com/repos/cockroachdb/cockroach/commits{/sha}","git_commits_url":"https://api.github.com/repos/cockroachdb/cockroach/git/commits{/sha}","comments_url":"https://api.github.com/repos/cockroachdb/cockroach/comments{/number}","issue_comment_url":"https://api.github.com/repos/cockroachdb/cockroach/issues/comments{/number}","contents_url":"https://api.github.com/repos/cockroachdb/cockroach/contents/{+path}","compare_url":"https://api.github.com/repos/cockroachdb/cockroach/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cockroachdb/cockroach/merges","archive_url":"https://api.github.com/repos/cockroachdb/cockroach/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cockroachdb/cockroach/downloads","issues_url":"https://api.github.com/repos/cockroachdb/cockroach/issues{/number}","pulls_url":"https://api.github.com/repos/cockroachdb/cockroach/pulls{/number}","milestones_url":"https://api.github.com/repos/cockroachdb/cockroach/milestones{/number}","notifications_url":"https://api.github.com/repos/cockroachdb/cockroach/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cockroachdb/cockroach/labels{/name}","releases_url":"https://api.github.com/repos/cockroachdb/cockroach/releases{/id}","created_at":"2014-02-06T00:18:47Z","updated_at":"2015-09-14T14:26:19Z","pushed_at":"2015-09-14T13:09:47Z","git_url":"git://github.com/cockroachdb/cockroach.git","ssh_url":"git@github.com:cockroachdb/cockroach.git","clone_url":"https://github.com/cockroachdb/cockroach.git","svn_url":"https://github.com/cockroachdb/cockroach","homepage":null,"size":53982,"stargazers_count":5247,"watchers_count":5247,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":425,"mirror_url":null,"open_issues_count":177,"forks":425,"open_issues":177,"watchers":5247,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484"},"html":{"href":"https://github.com/cockroachdb/cockroach/pull/2484"},"issue":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2484"},"comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/issues/2484/comments"},"review_comments":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484/comments"},"review_comment":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cockroachdb/cockroach/pulls/2484/commits"},"statuses":{"href":"https://api.github.com/repos/cockroachdb/cockroach/statuses/2c0555d4f3c7db651fd30d9c8ed450947bb9095f"}}}}