3 ms·
This is the compiled to Bash part. Sed is used because `bc -l` can return a float when integer is expected. Not sure if can be done better in generic case but i
by forgotpwd16 2y ago
This is the compiled to Bash part. Sed is used because `bc -l` can return a float when integer is expected. Not sure if can be done better in generic case but it isn't unheard. Certainly can be optimized for some cases. (Here e.g. can use Bash's built-in integer arithmetic.)
- kwhitefoot 2y agoBut why does it use bc in the first place? Bash does integer arithmetic perfectly well on its own. Amber claims to be type safe so it should have enough information to avoid the the use of bc in this case. Ah, just looked at the documentation. Amber doesn't have integer types just a number type. That means that any numerical operation in Amber is pretty much guaranteed to be very inefficient. It's a very strange choice to make because the underlying 'machine code' supports both integers and floating point.
- wrasee 2y agoThis is the first thing I noticed. Using ‘bc’ and ‘sed’ for integer comparison seems quite odd. But then they chose this for their front page example, the one that everyone will see, so I assumed this was to demonstrate something clever I just didn’t understand. I wonder what the motivation was to not have an integer type?
- queuebert 2y agoYou could also do the extremely readable `| cut -f1 -d.` which will do nothing for an integer.