{"id":593,"date":"2015-01-06T16:48:02","date_gmt":"2015-01-06T15:48:02","guid":{"rendered":"http:\/\/www.hauweele.net\/~gawen\/blog\/?p=593"},"modified":"2015-01-06T16:48:02","modified_gmt":"2015-01-06T15:48:02","slug":"fp-comparison-in-shell","status":"publish","type":"post","link":"https:\/\/hauweele.net\/~gawen\/blog\/?p=593","title":{"rendered":"FP comparison in Shell"},"content":{"rendered":"<p>People tend to not like Shell. But I do!<br \/>\nHere is a simple example, try this floating point comparison:<\/p>\n<pre>$ [ 0.1 -gt 0.01 ]\r\n[: 0.1: bad number\r\n<\/pre>\n<p>The shell itself cannot use float.<br \/>\nBut there are multiple workarounds.\u00a0Here is the one I prefer:<\/p>\n<pre>if rpnc \"$a\" \"$b\" - | grep \"^-\" &gt; \/dev\/null\r\nthen\r\n  echo \"a &lt; b\"\r\nfi\r\n<\/pre>\n<p>Although you may not have the <em>rpnc<\/em> command,\u00a0so here is another one:<\/p>\n<pre>if [ $(echo \"$a &lt; $b\" | bc) -eq 1 ]\r\nthen\r\n  echo \"a &lt; b\"\r\nfi<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>People tend to not like Shell. But I do! Here is a simple example, try this floating point comparison: $ [ 0.1 -gt 0.01 ] [: 0.1: bad number The shell itself cannot use float. But there are multiple workarounds.\u00a0Here &hellip; <a href=\"https:\/\/hauweele.net\/~gawen\/blog\/?p=593\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[534,532,530,529,535,531,533,30],"class_list":["post-593","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-bc","tag-comparison","tag-floating","tag-fp","tag-if","tag-point","tag-rpnc","tag-shell"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=593"}],"version-history":[{"count":0,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/593\/revisions"}],"wp:attachment":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}