Round to Nearest

I recently had to write some code to round a value to something other than the nearest integer, e.g. rounding a measurement to the nearest 0.5 or 0.1 unit.


RoundTo
To figure out how to do it, suppose we want to round to the nearest multiple of, say, 5.


Scale the number line from 0, 5, 10, ... to 0, 1, 2, ...


Round.


Then scale from 0, 1, 2... back to 0, 5, 10...

Extension to values other than 5 is straightforward.

The Lisp code:

(defun round-to (n m)
(if (or (null m) (zerop m))
n
(* (round (/ n (float m))) (float m))))


Comments

Words of Wisdom from The Bean Tap

This morning, at The Bean Tap:


Can't you see it? It's invisible!

     — Dylan



He’s about to slap the “old” right off your face.

     — Heather

Comments

Hope



During lunch today I was listening to a video featuring
Jordan Peterson and Ben Shapiro. Between 16:35 and 16:52 in the video, Peterson remarks:

"Well, it's partly because the problem with … the problem with relativism let's say … let's say that did produce a radical state of equality. Well the problem with that is that there's no "up". And the problem with there being no "up" is there's no hope. And the problem with that is that people actually live on hope."

Dogs, too.

My granddog, Titan, lives by hope. Hope that he will get treats, especially after going for a walk or when I come home. Here he is, live and unrehearsed, when I arrived home from lunch. He greets me at the door to the garage, then stops where we keep his treats in a niche above his food and water bowls. As I go by, he hopes that he'll get a bit of the waffles my wife made this morning.

I can't ever disappoint my dog.

Mlem.



Comments

January 1, 2018: Snow on Titan

snow.2018
It was snowing very lightly this morning. This is ten minutes worth of accumulation on Titan.


Read More...
Comments

The Trinity by Dale Tuggy : A Critique

Trinity.Tuggy

A Unitarian friend of mine loaned me this book as part of our ongoing debate about the nature of God. The Introduction isn't bad, but it contains the seeds of two problems that the author will have to address when discussing the alleged shortcomings of the doctrine of the Trinity. The first is the actual Biblical evidence. Anti-Trinitarians, in my experience, tend to focus on the writings of Church Fathers, creedal statements and their origins, political infighting, and so on. Indeed, the introduction beings with:


Read More...
Comments