From 19a7b4a287be6556f3a3de4cc7daa7edace92588 Mon Sep 17 00:00:00 2001 From: Nikolay Puzanov Date: Sun, 6 Nov 2022 14:23:18 +0300 Subject: [PATCH] Add round-to function --- embddr/common.scm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/embddr/common.scm b/embddr/common.scm index 48eacce..79c5414 100644 --- a/embddr/common.scm +++ b/embddr/common.scm @@ -5,7 +5,7 @@ (import (srfi srfi-1) (srfi srfi-60)) - (export log2 clog2 + (export log2 clog2 round-to one? power-of-two? curry curry-r transpose @@ -36,6 +36,11 @@ ;;; Check for (x == 1) (define (one? x) (= x 1)) +;;; Round to the 'n' decimal place +(define (round-to n num) + (let ((k (expt 10 n))) + (/ (round (* num k)) k))) + ;;; Currying ;;; Example: ((curry-r f 1) 2 3) -> (f 1 2 3) (define (curry f . args)