Faire flotter mon bateau (floating my boat)


I started a thread several years ago about doing maths in the shell (or scripted) - and I mentioned some stuff about using awk to do floating point, in the shell (or a shell script).

But I just learned today (someone shared a table on FB - about features of each shell - but - when I just went back there - Zuckerberg decided to refresh my feed and I’ve NO IDEA how to get that table back!) that ZSH can do floating point and I just tested it :

╭─x@titan /mnt/BARGEARSE/home/x/X/10base2/2023/12-December/002  
╰─➤  echo $((0.5*10.0))
╭─x@titan /mnt/BARGEARSE/home/x/X/10base2/2023/12-December/002  
╰─➤  echo $((0.5*61.0))
╭─x@titan /mnt/BARGEARSE/home/x/X/10base2/2023/12-December/002  
╰─➤  echo $((0.6*35))  

It’s not perfect - but my main use case of floating point in the shell is to convert hours / minutes to decimal values (and vice versa).

Which is a kinda coincidence - as I noticed @nevj 's timely suggestion for calculating if / when Xmas eve falls on a Sunday…

I had a shell script I wrote 5+ years ago to suggest the next train I could get (allowing for a 15 min walk to the station) to get home at the end of the day… I used “scale” and “bc” to do floating point (awk wasn’t cutting the mustard) arithmetic on time values…

So - I might - if I ever have the need, to write a shell script that calculates hours and minutes - write an actual ZSH script instead of a BASH script (or I guess I could just call ZSH in a BASH script ?).

But then again - I’m guessing Python probably has those features built in (e.g. “import datetime”).

And - ZSH’s floating point can leave kinda ugly results :

╭─x@titan ~/bin  ‹main*› 
╰─➤  echo $((21.0/60.0))                                                                                                                                           130 ↵

I’d need to investigate whether I can round that up to the next integer … Hmmm - but this kinda does it for me :

╭─x@titan ~/bin  ‹main*› 
╰─➤  echo $((21.0/60.0*100))

The reason I chose “21” and 0.35, that’s 'cause in the 80’s and early 90’s I worked for the Commonwealth government, and our working day was 7.35 hours, or 7’21" - was it like that for you at the CSIRO @nevj ? Seemed like a strange, almost arbitrary value, but it was 'cause we were on a 73.5 hour fortnight - no idea where that idea came from… I think at least the Australian Tax Office, is still on those hours - it was part of “flexi time” - i.e. you’d build up enough extra hours (e.g. working from 9-5 with an hour for lunch) to maybe take an afternoon off, or go to the pub for lunch on a Friday and NOT COME BACK :smiley: . After that job - I worked for the WA state government (both jobs were in hospitals) and we were on 7.5 hour days, would work 8 hours, and have an RDO (rostered day off) every fortnight - that’s how it was supposed to work, but I never took my RDO’s…

Yes, 9.00am to 4.36pm.
Sign the book as you come in. Red line drawn in book at 9.10.
Until flextime came in

I remember school hours… 8.50 to 3.05. Not sure how that
works today.

Back in the 70’s (and late 60’s I guess - I was in kinder 1967, 1st Class 1968, 2nd class 1969 - 3rd class 1970 - at two different Catholic convent schools in Newcastle NSW - don’t remember start and finish times, just remember the whole daily ordeal was TOO LONG!) - at high school, different schools had different start and finish times, and different period times…

My first high school was Perth Modern School, I think it was 8:30 to 3:00 pm or maybe 3:20? The period lengths were 40 minutes each, some things like sport were a double period. At the end of that year my family moved to Melbourne, and I went to a high school in Elwood (sorta part of St Kilda) and periods were 50 minutes each and the school day seemed to last longer - and there were sometimes like “double-periods” of maths - and I LOATHED maths… Anyway - I fell foul of a bully and one teacher the following year and mostly played truant (wagged school) and didn’t pass year 10.

Went to re-enroll for year 10 and they said they didn’t want me back at the school as I was a disruptive tearaway :smiley: and a bad influence.

I came home and told my mum, I was finished with school - WOOHOO!

She phoned my Dad at work (she had to go to a phone booth - we never had the phone on when I was growing up) and then she went shopping (using public transport - we didn’t have a car either!) for a school that would take me - and found one not too far - a “vocational” high school called a “Technical College”. Anyway - that school had a shorter day, and 40 minute periods! Was my best year of school life and high school - South Melbourne Technical College (and was also a TAFE for night school tradies, my grandfather went there for his plumbing apprenticeship)!

Then end of that year, my Dad got itchy feet again, and decided were all going back to Perth, and I ended up back at the same high school I went to for first year high (in WA - primary school ended at the end of Grade 7, same in Queensland, but NSW and Vic you went to highschool in your 7th year of schooling - I believe it’s now uniform across Australia, i.e. in WA year 7 is now first year of high school).

1 Like

It came up in my feed again several hours later :

And looky there - I used to prefer KSH and used it on Solaris for 20+ years and never knew it had Floating point support!

Learn something new every day!

1 Like

The old BSD preference was to work in csh and write scripts in sh.

I think nushell has floating point.

1 Like