Why are round/floor/ceiling/truncate limited to real numbers? What stops them from being extended to all numbers?
Mathematica defines complex floor with: > Floor <http://reference.wolfram.com/mathematica/ref/Floor.html> applies > separately to real and imaginary parts of complex numbers Of course, that might just be Mathematica's own idea of what a complex floor is. Or am I too simply lazy to define the following? (define (complex-floor x) (make-rectangular (floor (real-part x)) (floor (imag-part x)))) Tim On 10 June 2013 17:18, Bradley Lucier <luc...@math.purdue.edu> wrote: > Re: > >> FWIW, I would have at least written: >> >> ((qty (in-range 0 (add1 (min (floor (/ weight-left weight)) >> (floor (/ volume-left volume))))))) >> > > I have now seen the > > (floor (/ a b)) > > idiom a number of times, and wonder why people prefer it to > > (quotient a b) > > Normally, to calculate (/ a b) where a and b are exact integers requires > one to calculate (gcd a b) to put the fraction into lowest terms > p/q=(quotient a (gcd a b))/(quotient b (gcd a b)); then, to calculate > (floor p/q), one must calculate (quotient p q). > > For large integers of size $N$ bits, (gcd a b) takes $O(N\log^2(N))$ > fixnum operations, where quotient takes $O(N\log N)$ operations. This > assumes Fourier-based methods for bignum multiplication; for more direct > methods, the difference in operation count is larger. > > In any case, the (floor (/ ...)) idiom takes noticeably more time than > (quotient ...). If one knows that a and b are positive integers, they give > the same results. > > This is an argument not to use (floor (/ ...)). Are there arguments in > favor of this idiom? > > Brad > ____________________ > Racket Users list: > http://lists.racket-lang.org/**users <http://lists.racket-lang.org/users> > -- | Tim Brown <tim.br...@timb.net> | M:+44(0)7771714159 | H:+44(0)1372747875 |
____________________ Racket Users list: http://lists.racket-lang.org/users