5 ms·
Now show me how to add 1.5 and 0.5. bash-3.2$ echo $((1.5+0.5)) bash: 1.5+0.5: syntax error: invalid arithmetic operator (error token is ".5+0.5") htt
by DonHopkins 8y ago
Now show me how to add 1.5 and 0.5.
bash-3.2$ echo $((1.5+0.5))
bash: 1.5+0.5: syntax error: invalid arithmetic operator (error token is ".5+0.5")
https://unix.stackexchange.com/questions/40786/how-to-do-integer-float-calculations-in-bash-or-other-languages-frameworks https://unix.stackexchange.com/questions/40786/how-to-do-int...
I gave up INTEGER BASIC for APPLESOFT several decades ago, and never looked back.
(LOADING INTEGER INTO LANGUAGE CARD)
]INT
>PRINT 1.5 + 0.5
*** SYNTAX ERROR
>FP
]PRINT 1.5 + 0.5
2
It's 2019, and you're struggling to do in bash what you could have done on an Apple ][ in 1979, but the syntax you need to use is even WORSE than BASIC, so your code looks like line noise from when your mom picks up the phone while you're using a 300 baud modem. Is that really progress?
https://en.wikipedia.org/wiki/Integer_BASIC https://en.wikipedia.org/wiki/Integer_BASIC
>Integer BASIC was phased out in favor of Applesoft BASIC starting with the Apple II Plus in 1979. This was a licensed but modified version of Microsoft BASIC, which included the floating point support missing in Integer BASIC.
https://en.wikipedia.org/wiki/Applesoft_BASIC https://en.wikipedia.org/wiki/Applesoft_BASIC
>Applesoft BASIC is a dialect of Microsoft BASIC, developed by Marc McDonald and Ric Weiland, supplied with the Apple II series of computers. It supersedes Integer BASIC and is the BASIC in ROM in all Apple II series computers after the original Apple II model. It is also referred to as FP BASIC (from "floating point") because of the Apple DOS command used to invoke it, instead of INT for Integer BASIC.
Notice that there are even machine language instructions for cos, atan, tan, sin, ln, etc. How do you call those instructions in bash?
https://docs.oracle.com/cd/E18752_01/html/817-5477/eoizy.html https://docs.oracle.com/cd/E18752_01/html/817-5477/eoizy.htm...
>x86 Assembly Language Reference Manual: Floating-Point Instructions
>The floating point instructions operate on floating-point, integer, and binary coded decimal (BCD) operands.
- js2 8y agobash is Turing complete... the rest is left as an exercise to the reader. :-)
- DonHopkins 8y agoSome people just love to dive into the deep end of the Turing Tarpit, because their point is to be as wasteful and inefficient as possible. Thus my point about buying gum with Bitcoin and rolling coal to trigger the libs. https://en.wikipedia.org/wiki/Turing_tarpit https://en.wikipedia.org/wiki/Turing_tarpit >54. Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy. But I think that most people who use bash simply have no clue how expensive forking another process is, and not enough experience to realize that software always ends up growing up to be much more complex than they originally expected, and think that "1+1" is as much arithmetic as they will ever need. https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule >Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp. https://en.wikipedia.org/wiki/Jamie_Zawinski#Principles https://en.wikipedia.org/wiki/Jamie_Zawinski#Principles >Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can.
- js2 8y agoI really thought you were being facetious comparing bash and forking to bitcoin. Shell scripts aren't so terrible and you wouldn't use them in performance critical scenarios. It's not like all our CPUs are running at 100% utilization. You're talking to someone who ran a web farm in the 90s so yeah, I saw the evolution from CGI to mod-perl and on. I mean I know the cost of forking. But come on, aren't you taking your criticism a bit far? I also had an Apple ][+. Actually, one wasn't available so we Frankensteined one together from an Apple ][ and an Applesoft language card by swapping the motherboard ROMs and language card ROMs.
- DonHopkins 8y agoAs long as people don't understand how wasteful and inefficient bash scripts are, I haven't taken my criticism far enough. ;) We both have some perspective from the Apple ][ days, and can appreciate how astronomically fast computers are compared to how slow they used to be. But doesn't it give you pause (literally and figuratively) when you see people thoughtlessly and casually write code in 2019 that runs slower on a high-end MacBook Pro than the equivalent code would run on an Apple ][ in 1979? People should take a momemt to reflect on what they're trying to accomplish and if there are better ways of going about it, before writing Rube-Goldbergesqe bash scripts heavily punctuated with line noise, haphazardly stringing together Unix processes and temporary files with cryptically abbreviated commands using mysteriously curt flags and parameters (like "dc -l", or is it "bc -l", and is that dash-ell or dash-one? I can't remember, and we haven't even gotten to the part about how I have to quote and escape the arithmetic expression parameter)! It's not as if they're making thoughtful trade-offs, and that as a result of choosing to use bash despite all its weaknesses, they're actually developing more robust, easier to read and maintain code than they would have had they used Python.
- saagarjha 8y ago> Notice that there are even machine language instructions for cos, atan, tan, sin, ln, etc. How do you call those instructions in bash? How do you call those in Python ;) Fundamentally, you're making a big deal about something that isn't really that horrible. Not everyone has Python on their system, and a fork() is not a terribly costly operation for a shell script. Sure, it might take an extra microwatt, but arguing that this is the same as Bitcoin mining or rolling coal is an argument in the extreme.
- DonHopkins 8y ago>>> import math >>> help(math.sin) Help on built-in function sin in module math: sin(...) sin(x) Return the sine of x (measured in radians). >>> print math.sin(math.pi) 1.22464679915e-16 Name somebody in the real world who doesn't work full time for the Computer Museum, who doesn't already have Python on their system, and can't easily install it? That's a straw man argument and in no way justifies using bash in 2019. If you were able to easily add 1.5 and 0.5 in APPLESOFT on your Apple ][+ by typing "PRINT 1.5 + 0.5" 40 years ago, and you could even add 1 and 1 by typing "PRINT 1 + 1" without decorating it with a bunch of ridiculous punctuation ((double parens, really?)) in INTEGER BASIC on your APPLE ][, you would see bash's lack of that ability as pretty extreme. Sheez, even APPLESOFT had SIN and COS and SQR. But not bash. https://www.calormen.com/jsbasic/reference.html https://www.calormen.com/jsbasic/reference.html
- saagarjha 8y ago> Name somebody in the real world who doesn't work full time for the Computer Museum, who doesn't already have Python on their system, and can't easily install it? That's a straw man argument and in no way justifies using bash in 2019. Me: I SSH into systems that I don't have permission to install new things on. > without decorating it with a bunch of ridiculous punctuation ((double parens, really?)) This is a nitpick, and you're missing the point: bash isn't the best tool to do numerical computation because it can call out to other programs with very little syntactical overhead. The fact that it has the ability to do basic arithmetic is something I brought up to be snarky: this feature is rarely used in practice.
- stevekemp 8y ago> Notice that there are even machine language instructions for cos, atan, tan, sin, ln, etc. How do you call those instructions in bash? Simple! You shell out to your math-compiler: https://github.com/skx/math-compiler/ https://github.com/skx/math-compiler/ That compiles your math down to assembly language, which has got to make sure they're super-fast, right? ;)
- DonHopkins 8y agoThe compiler/assembler/disassembler/debugger should be built into the shell so you don't have to fork out to it of couse, just like ITS DDT at the MIT-AI Lab in 1969! ;) https://en.wikipedia.org/wiki/Incompatible_Timesharing_System https://en.wikipedia.org/wiki/Incompatible_Timesharing_Syste... https://dspace.mit.edu/handle/1721.1/6153 https://dspace.mit.edu/handle/1721.1/6153 https://github.com/PDP-10/its/blob/master/doc/info/ddt.33 https://github.com/PDP-10/its/blob/master/doc/info/ddt.33 https://github.com/PDP-10/its/blob/master/doc/_info_/ddtord.1462 https://github.com/PDP-10/its/blob/master/doc/_info_/ddtord.... https://github.com/PDP-10/its/blob/master/doc/debugging.md https://github.com/PDP-10/its/blob/master/doc/debugging.md