{"action":"created","comment":{"url":"https://api.github.com/repos/diffblue/cbmc/pulls/comments/167246300","pull_request_review_id":95441868,"id":167246300,"diff_hunk":"@@ -50,4 +52,40 @@ class expr2javat:public expr2ct\n std::string expr2java(const exprt &expr, const namespacet &ns);\n std::string type2java(const typet &type, const namespacet &ns);\n \n+/// Convert floating point number to a string without printing\n+/// unnecessary zeros. Prints decimal if precision is not lost.\n+/// Prints hexadecimal otherwise, and/or java-friendly NaN and Infinity\n+template <typename float_type>\n+std::string floating_point_to_java_string(float_type value)\n+{\n+  static_assert(sizeof(float) == 4, \"Float should be 32-bit type\");\n+  static_assert(sizeof(double) == 8, \"Double should be 64-bit type\");\n+  const auto is_float = std::is_same<float_type, float>::value;\n+  static const std::string class_name = is_float ? \"Float\" : \"Double\";\n+  if(std::isnan(value))\n+    return class_name + \".NaN\";\n+  if(std::isinf(value))\n+    return class_name + \".POSITIVE_INFINITY\";\n+  if(std::isinf(-value))\n+    return class_name + \".NEGATIVE_INFINITY\";\n+  const auto raw_decimal = std::to_string(value);\n+  const auto decimal = raw_decimal.find('.') == std::string::npos\n+                         ? raw_decimal + \".0\"\n+                         : raw_decimal;\n+  const bool is_lossless = std::stod(decimal == value);\n+  const auto lossless = [&] { // NOLINT\n+    if(is_lossless)","path":"src/java_bytecode/expr2java.h","position":35,"original_position":35,"commit_id":"4e6346c58efaf20974b62bea669c73434d83f4f9","original_commit_id":"4e6346c58efaf20974b62bea669c73434d83f4f9","user":{"login":"smowton","id":283483,"avatar_url":"https://avatars3.githubusercontent.com/u/283483?v=4","gravatar_id":"","url":"https://api.github.com/users/smowton","html_url":"https://github.com/smowton","followers_url":"https://api.github.com/users/smowton/followers","following_url":"https://api.github.com/users/smowton/following{/other_user}","gists_url":"https://api.github.com/users/smowton/gists{/gist_id}","starred_url":"https://api.github.com/users/smowton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smowton/subscriptions","organizations_url":"https://api.github.com/users/smowton/orgs","repos_url":"https://api.github.com/users/smowton/repos","events_url":"https://api.github.com/users/smowton/events{/privacy}","received_events_url":"https://api.github.com/users/smowton/received_events","type":"User","site_admin":false},"body":"This is backwards I think, we should use hexfloat if the decimal representation is **lossy**","created_at":"2018-02-09T14:48:37Z","updated_at":"2018-02-09T14:49:27Z","html_url":"https://github.com/diffblue/cbmc/pull/1808#discussion_r167246300","pull_request_url":"https://api.github.com/repos/diffblue/cbmc/pulls/1808","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/diffblue/cbmc/pulls/comments/167246300"},"html":{"href":"https://github.com/diffblue/cbmc/pull/1808#discussion_r167246300"},"pull_request":{"href":"https://api.github.com/repos/diffblue/cbmc/pulls/1808"}}},"pull_request":{"url":"https://api.github.com/repos/diffblue/cbmc/pulls/1808","id":167725583,"html_url":"https://github.com/diffblue/cbmc/pull/1808","diff_url":"https://github.com/diffblue/cbmc/pull/1808.diff","patch_url":"https://github.com/diffblue/cbmc/pull/1808.patch","issue_url":"https://api.github.com/repos/diffblue/cbmc/issues/1808","number":1808,"state":"open","locked":false,"title":"Refactor and expose floating point to java conversion in expr2java.h","user":{"login":"LAJW","id":11063742,"avatar_url":"https://avatars2.githubusercontent.com/u/11063742?v=4","gravatar_id":"","url":"https://api.github.com/users/LAJW","html_url":"https://github.com/LAJW","followers_url":"https://api.github.com/users/LAJW/followers","following_url":"https://api.github.com/users/LAJW/following{/other_user}","gists_url":"https://api.github.com/users/LAJW/gists{/gist_id}","starred_url":"https://api.github.com/users/LAJW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LAJW/subscriptions","organizations_url":"https://api.github.com/users/LAJW/orgs","repos_url":"https://api.github.com/users/LAJW/repos","events_url":"https://api.github.com/users/LAJW/events{/privacy}","received_events_url":"https://api.github.com/users/LAJW/received_events","type":"User","site_admin":false},"body":"This change exposes new `floating_point_to_java_string` function. It lets the user convert floating point numbers to Java-compatible strings without having to cast them to expression and creating an\r\nunnecessary namespace beforehand. Also, prints Java floats in decimal format if no data is lost in the process, otherwise falls back to printing hex.","created_at":"2018-02-07T15:33:08Z","updated_at":"2018-02-09T14:49:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d4997f9e3ec763c8fa166a3168c3036a734998af","assignee":null,"assignees":[],"requested_reviewers":[{"login":"cesaro","id":143977,"avatar_url":"https://avatars1.githubusercontent.com/u/143977?v=4","gravatar_id":"","url":"https://api.github.com/users/cesaro","html_url":"https://github.com/cesaro","followers_url":"https://api.github.com/users/cesaro/followers","following_url":"https://api.github.com/users/cesaro/following{/other_user}","gists_url":"https://api.github.com/users/cesaro/gists{/gist_id}","starred_url":"https://api.github.com/users/cesaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cesaro/subscriptions","organizations_url":"https://api.github.com/users/cesaro/orgs","repos_url":"https://api.github.com/users/cesaro/repos","events_url":"https://api.github.com/users/cesaro/events{/privacy}","received_events_url":"https://api.github.com/users/cesaro/received_events","type":"User","site_admin":false},{"login":"kroening","id":1830565,"avatar_url":"https://avatars0.githubusercontent.com/u/1830565?v=4","gravatar_id":"","url":"https://api.github.com/users/kroening","html_url":"https://github.com/kroening","followers_url":"https://api.github.com/users/kroening/followers","following_url":"https://api.github.com/users/kroening/following{/other_user}","gists_url":"https://api.github.com/users/kroening/gists{/gist_id}","starred_url":"https://api.github.com/users/kroening/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kroening/subscriptions","organizations_url":"https://api.github.com/users/kroening/orgs","repos_url":"https://api.github.com/users/kroening/repos","events_url":"https://api.github.com/users/kroening/events{/privacy}","received_events_url":"https://api.github.com/users/kroening/received_events","type":"User","site_admin":false},{"login":"mgudemann","id":2590540,"avatar_url":"https://avatars0.githubusercontent.com/u/2590540?v=4","gravatar_id":"","url":"https://api.github.com/users/mgudemann","html_url":"https://github.com/mgudemann","followers_url":"https://api.github.com/users/mgudemann/followers","following_url":"https://api.github.com/users/mgudemann/following{/other_user}","gists_url":"https://api.github.com/users/mgudemann/gists{/gist_id}","starred_url":"https://api.github.com/users/mgudemann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgudemann/subscriptions","organizations_url":"https://api.github.com/users/mgudemann/orgs","repos_url":"https://api.github.com/users/mgudemann/repos","events_url":"https://api.github.com/users/mgudemann/events{/privacy}","received_events_url":"https://api.github.com/users/mgudemann/received_events","type":"User","site_admin":false},{"login":"peterschrammel","id":4222448,"avatar_url":"https://avatars3.githubusercontent.com/u/4222448?v=4","gravatar_id":"","url":"https://api.github.com/users/peterschrammel","html_url":"https://github.com/peterschrammel","followers_url":"https://api.github.com/users/peterschrammel/followers","following_url":"https://api.github.com/users/peterschrammel/following{/other_user}","gists_url":"https://api.github.com/users/peterschrammel/gists{/gist_id}","starred_url":"https://api.github.com/users/peterschrammel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterschrammel/subscriptions","organizations_url":"https://api.github.com/users/peterschrammel/orgs","repos_url":"https://api.github.com/users/peterschrammel/repos","events_url":"https://api.github.com/users/peterschrammel/events{/privacy}","received_events_url":"https://api.github.com/users/peterschrammel/received_events","type":"User","site_admin":false},{"login":"chrisr-diffblue","id":32060010,"avatar_url":"https://avatars2.githubusercontent.com/u/32060010?v=4","gravatar_id":"","url":"https://api.github.com/users/chrisr-diffblue","html_url":"https://github.com/chrisr-diffblue","followers_url":"https://api.github.com/users/chrisr-diffblue/followers","following_url":"https://api.github.com/users/chrisr-diffblue/following{/other_user}","gists_url":"https://api.github.com/users/chrisr-diffblue/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisr-diffblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisr-diffblue/subscriptions","organizations_url":"https://api.github.com/users/chrisr-diffblue/orgs","repos_url":"https://api.github.com/users/chrisr-diffblue/repos","events_url":"https://api.github.com/users/chrisr-diffblue/events{/privacy}","received_events_url":"https://api.github.com/users/chrisr-diffblue/received_events","type":"User","site_admin":false}],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/diffblue/cbmc/pulls/1808/commits","review_comments_url":"https://api.github.com/repos/diffblue/cbmc/pulls/1808/comments","review_comment_url":"https://api.github.com/repos/diffblue/cbmc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/diffblue/cbmc/issues/1808/comments","statuses_url":"https://api.github.com/repos/diffblue/cbmc/statuses/4e6346c58efaf20974b62bea669c73434d83f4f9","head":{"label":"LAJW:lajw/floating-point-to-java-string","ref":"lajw/floating-point-to-java-string","sha":"4e6346c58efaf20974b62bea669c73434d83f4f9","user":{"login":"LAJW","id":11063742,"avatar_url":"https://avatars2.githubusercontent.com/u/11063742?v=4","gravatar_id":"","url":"https://api.github.com/users/LAJW","html_url":"https://github.com/LAJW","followers_url":"https://api.github.com/users/LAJW/followers","following_url":"https://api.github.com/users/LAJW/following{/other_user}","gists_url":"https://api.github.com/users/LAJW/gists{/gist_id}","starred_url":"https://api.github.com/users/LAJW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LAJW/subscriptions","organizations_url":"https://api.github.com/users/LAJW/orgs","repos_url":"https://api.github.com/users/LAJW/repos","events_url":"https://api.github.com/users/LAJW/events{/privacy}","received_events_url":"https://api.github.com/users/LAJW/received_events","type":"User","site_admin":false},"repo":{"id":96877268,"name":"cbmc","full_name":"LAJW/cbmc","owner":{"login":"LAJW","id":11063742,"avatar_url":"https://avatars2.githubusercontent.com/u/11063742?v=4","gravatar_id":"","url":"https://api.github.com/users/LAJW","html_url":"https://github.com/LAJW","followers_url":"https://api.github.com/users/LAJW/followers","following_url":"https://api.github.com/users/LAJW/following{/other_user}","gists_url":"https://api.github.com/users/LAJW/gists{/gist_id}","starred_url":"https://api.github.com/users/LAJW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LAJW/subscriptions","organizations_url":"https://api.github.com/users/LAJW/orgs","repos_url":"https://api.github.com/users/LAJW/repos","events_url":"https://api.github.com/users/LAJW/events{/privacy}","received_events_url":"https://api.github.com/users/LAJW/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/LAJW/cbmc","description":"C Bounded Model Checker","fork":true,"url":"https://api.github.com/repos/LAJW/cbmc","forks_url":"https://api.github.com/repos/LAJW/cbmc/forks","keys_url":"https://api.github.com/repos/LAJW/cbmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/LAJW/cbmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/LAJW/cbmc/teams","hooks_url":"https://api.github.com/repos/LAJW/cbmc/hooks","issue_events_url":"https://api.github.com/repos/LAJW/cbmc/issues/events{/number}","events_url":"https://api.github.com/repos/LAJW/cbmc/events","assignees_url":"https://api.github.com/repos/LAJW/cbmc/assignees{/user}","branches_url":"https://api.github.com/repos/LAJW/cbmc/branches{/branch}","tags_url":"https://api.github.com/repos/LAJW/cbmc/tags","blobs_url":"https://api.github.com/repos/LAJW/cbmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/LAJW/cbmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/LAJW/cbmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/LAJW/cbmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/LAJW/cbmc/statuses/{sha}","languages_url":"https://api.github.com/repos/LAJW/cbmc/languages","stargazers_url":"https://api.github.com/repos/LAJW/cbmc/stargazers","contributors_url":"https://api.github.com/repos/LAJW/cbmc/contributors","subscribers_url":"https://api.github.com/repos/LAJW/cbmc/subscribers","subscription_url":"https://api.github.com/repos/LAJW/cbmc/subscription","commits_url":"https://api.github.com/repos/LAJW/cbmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/LAJW/cbmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/LAJW/cbmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/LAJW/cbmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/LAJW/cbmc/contents/{+path}","compare_url":"https://api.github.com/repos/LAJW/cbmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/LAJW/cbmc/merges","archive_url":"https://api.github.com/repos/LAJW/cbmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/LAJW/cbmc/downloads","issues_url":"https://api.github.com/repos/LAJW/cbmc/issues{/number}","pulls_url":"https://api.github.com/repos/LAJW/cbmc/pulls{/number}","milestones_url":"https://api.github.com/repos/LAJW/cbmc/milestones{/number}","notifications_url":"https://api.github.com/repos/LAJW/cbmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/LAJW/cbmc/labels{/name}","releases_url":"https://api.github.com/repos/LAJW/cbmc/releases{/id}","deployments_url":"https://api.github.com/repos/LAJW/cbmc/deployments","created_at":"2017-07-11T09:41:59Z","updated_at":"2017-07-11T09:42:07Z","pushed_at":"2018-02-09T14:38:58Z","git_url":"git://github.com/LAJW/cbmc.git","ssh_url":"git@github.com:LAJW/cbmc.git","clone_url":"https://github.com/LAJW/cbmc.git","svn_url":"https://github.com/LAJW/cbmc","homepage":"http://www.cprover.org/cbmc","size":26806,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"diffblue:develop","ref":"develop","sha":"ae6775a3594ee2aeed8d0b498e50d7737f87b2a6","user":{"login":"diffblue","id":17216098,"avatar_url":"https://avatars0.githubusercontent.com/u/17216098?v=4","gravatar_id":"","url":"https://api.github.com/users/diffblue","html_url":"https://github.com/diffblue","followers_url":"https://api.github.com/users/diffblue/followers","following_url":"https://api.github.com/users/diffblue/following{/other_user}","gists_url":"https://api.github.com/users/diffblue/gists{/gist_id}","starred_url":"https://api.github.com/users/diffblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diffblue/subscriptions","organizations_url":"https://api.github.com/users/diffblue/orgs","repos_url":"https://api.github.com/users/diffblue/repos","events_url":"https://api.github.com/users/diffblue/events{/privacy}","received_events_url":"https://api.github.com/users/diffblue/received_events","type":"Organization","site_admin":false},"repo":{"id":51877056,"name":"cbmc","full_name":"diffblue/cbmc","owner":{"login":"diffblue","id":17216098,"avatar_url":"https://avatars0.githubusercontent.com/u/17216098?v=4","gravatar_id":"","url":"https://api.github.com/users/diffblue","html_url":"https://github.com/diffblue","followers_url":"https://api.github.com/users/diffblue/followers","following_url":"https://api.github.com/users/diffblue/following{/other_user}","gists_url":"https://api.github.com/users/diffblue/gists{/gist_id}","starred_url":"https://api.github.com/users/diffblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diffblue/subscriptions","organizations_url":"https://api.github.com/users/diffblue/orgs","repos_url":"https://api.github.com/users/diffblue/repos","events_url":"https://api.github.com/users/diffblue/events{/privacy}","received_events_url":"https://api.github.com/users/diffblue/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/diffblue/cbmc","description":"C Bounded Model Checker","fork":false,"url":"https://api.github.com/repos/diffblue/cbmc","forks_url":"https://api.github.com/repos/diffblue/cbmc/forks","keys_url":"https://api.github.com/repos/diffblue/cbmc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/diffblue/cbmc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/diffblue/cbmc/teams","hooks_url":"https://api.github.com/repos/diffblue/cbmc/hooks","issue_events_url":"https://api.github.com/repos/diffblue/cbmc/issues/events{/number}","events_url":"https://api.github.com/repos/diffblue/cbmc/events","assignees_url":"https://api.github.com/repos/diffblue/cbmc/assignees{/user}","branches_url":"https://api.github.com/repos/diffblue/cbmc/branches{/branch}","tags_url":"https://api.github.com/repos/diffblue/cbmc/tags","blobs_url":"https://api.github.com/repos/diffblue/cbmc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/diffblue/cbmc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/diffblue/cbmc/git/refs{/sha}","trees_url":"https://api.github.com/repos/diffblue/cbmc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/diffblue/cbmc/statuses/{sha}","languages_url":"https://api.github.com/repos/diffblue/cbmc/languages","stargazers_url":"https://api.github.com/repos/diffblue/cbmc/stargazers","contributors_url":"https://api.github.com/repos/diffblue/cbmc/contributors","subscribers_url":"https://api.github.com/repos/diffblue/cbmc/subscribers","subscription_url":"https://api.github.com/repos/diffblue/cbmc/subscription","commits_url":"https://api.github.com/repos/diffblue/cbmc/commits{/sha}","git_commits_url":"https://api.github.com/repos/diffblue/cbmc/git/commits{/sha}","comments_url":"https://api.github.com/repos/diffblue/cbmc/comments{/number}","issue_comment_url":"https://api.github.com/repos/diffblue/cbmc/issues/comments{/number}","contents_url":"https://api.github.com/repos/diffblue/cbmc/contents/{+path}","compare_url":"https://api.github.com/repos/diffblue/cbmc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/diffblue/cbmc/merges","archive_url":"https://api.github.com/repos/diffblue/cbmc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/diffblue/cbmc/downloads","issues_url":"https://api.github.com/repos/diffblue/cbmc/issues{/number}","pulls_url":"https://api.github.com/repos/diffblue/cbmc/pulls{/number}","milestones_url":"https://api.github.com/repos/diffblue/cbmc/milestones{/number}","notifications_url":"https://api.github.com/repos/diffblue/cbmc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/diffblue/cbmc/labels{/name}","releases_url":"https://api.github.com/repos/diffblue/cbmc/releases{/id}","deployments_url":"https://api.github.com/repos/diffblue/cbmc/deployments","created_at":"2016-02-16T23:03:52Z","updated_at":"2018-02-06T19:52:55Z","pushed_at":"2018-02-09T14:39:00Z","git_url":"git://github.com/diffblue/cbmc.git","ssh_url":"git@github.com:diffblue/cbmc.git","clone_url":"https://github.com/diffblue/cbmc.git","svn_url":"https://github.com/diffblue/cbmc","homepage":"http://www.cprover.org/cbmc","size":27819,"stargazers_count":96,"watchers_count":96,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":86,"mirror_url":null,"archived":false,"open_issues_count":317,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":86,"open_issues":317,"watchers":96,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/diffblue/cbmc/pulls/1808"},"html":{"href":"https://github.com/diffblue/cbmc/pull/1808"},"issue":{"href":"https://api.github.com/repos/diffblue/cbmc/issues/1808"},"comments":{"href":"https://api.github.com/repos/diffblue/cbmc/issues/1808/comments"},"review_comments":{"href":"https://api.github.com/repos/diffblue/cbmc/pulls/1808/comments"},"review_comment":{"href":"https://api.github.com/repos/diffblue/cbmc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/diffblue/cbmc/pulls/1808/commits"},"statuses":{"href":"https://api.github.com/repos/diffblue/cbmc/statuses/4e6346c58efaf20974b62bea669c73434d83f4f9"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"smowton"}}