Search found 127 matches
- Fri Nov 02, 2012 7:01 am
- Forum: Common Lisp
- Topic: A way to convert a float to integer w/o impact on memory?
- Replies: 9
- Views: 14116
Re: A way to convert a float to integer w/o impact on memory
Oh, integers of course. OK, I had dim memories there was something like that in this book... time to look into it again. Thanks!
- Fri Nov 02, 2012 4:05 am
- Forum: Common Lisp
- Topic: A way to convert a float to integer w/o impact on memory?
- Replies: 9
- Views: 14116
Re: A way to convert a float to integer w/o impact on memory
Thanks for the last version. That wasn't a serious test, actually there are many non-trivial ways to round up to the closest power of two fast (or, perhaps even faster then your suggestion). I realize now that floor is not the culprit, but why would log cons any memory? Is this something that is inh...
- Fri Nov 02, 2012 1:45 am
- Forum: Common Lisp
- Topic: A way to convert a float to integer w/o impact on memory?
- Replies: 9
- Views: 14116
Re: A way to convert a float to integer w/o impact on memory
Below is my complete test: (defun next-power-two-loop (x) (declare (optimize (debug 0) (safety 0) (space 0) (speed 3))) (declare (type fixnum x)) (if (and (> x 0) (= (logand x (1- x)) 0)) x (loop with result fixnum = 1 do (setq result (ash result 1)) do (when (> result x) (return result))))) (defun ...
- Thu Nov 01, 2012 11:35 pm
- Forum: Common Lisp
- Topic: A way to convert a float to integer w/o impact on memory?
- Replies: 9
- Views: 14116
Re: A way to convert a float to integer w/o impact on memory
Hm... after some thought... how many bits is a fixnum on a 64 bit system? I think this must have been a problem then. In my test no value is larger then 2^31, but what if they can't be even this big and it creates long integers?
- Thu Nov 01, 2012 2:00 pm
- Forum: Common Lisp
- Topic: A way to convert a float to integer w/o impact on memory?
- Replies: 9
- Views: 14116
A way to convert a float to integer w/o impact on memory?
I've looked into all rounding / truncating / flooring functions that I know, but all of them return multiple values, and, as an artefact, even if the second value isn't used, they create and immediately dispose of new conses. This later causes GC to kick in and can slow down the execution at random ...
- Thu Nov 01, 2012 1:41 pm
- Forum: Common Lisp
- Topic: Quazi-quote, missing one evaluation
- Replies: 2
- Views: 5586
Re: Quazi-quote, missing one evaluation
Oh, sorry, I've totally missed this reply! Although, too late, thanks!
- Tue Oct 02, 2012 1:24 am
- Forum: Common Lisp
- Topic: Quazi-quote, missing one evaluation
- Replies: 2
- Views: 5586
Quazi-quote, missing one evaluation
Hi. I'm trying to come up with a simple table to object mapping (a learning exercise for now, not a real thing). Below is my code, where I can achieve what I need, but in a clumsy way: (defclass db-object () ()) (defun slot-list-from-query (query) (format t "slot-list-from-query: ~s~&"...
- Mon Sep 24, 2012 1:30 am
- Forum: Common Lisp
- Topic: Binary tree insert.
- Replies: 4
- Views: 7500
Re: Binary tree insert.
You could do a doubly linked list - that way finding the parent of the leaf becomes trivial, but another, perhaps simpler way, if all nodes are unique would be to have a hash-map alongisde the list, which would contain all nodes in the format key = child, value = parent.
- Sat Sep 15, 2012 11:00 am
- Forum: Common Lisp
- Topic: Printing a list of lists
- Replies: 6
- Views: 9649
Re: Printing a list of lists
One more way to do it: (defun example () (loop for (a b) in '((:question "A?" :answer "A!") (:question "B?" :answer "B!") (:question "C?" :answer "C!")) do (format t "a: ~s, b: ~s~&" a b))) This is called destructuring bind, h...
- Mon Sep 10, 2012 3:26 am
- Forum: Common Lisp
- Topic: Is there a direct calculation for gradient descent?
- Replies: 5
- Views: 9345
Re: Is there a direct calculation for gradient descent?
Aha, I see, thanks for clarification!