Re: [racket] error: degrees-complex: 360.0

2014-05-17 Thread Sean Kanaley
What's wrong with the user parameterizing it like this? To save you from having to read the whole thing, it randomly makes digits that belong to either the integer or fractional portion where the user chooses the max number of digits to generate. ;ms = max sig fig count, rs = rand sig fig count

Re: [racket] error: degrees-complex: 360.0

2014-05-16 Thread Neil Toronto
There's a random-real generator in math/private/utils/flonum-tests.rkt. The generator Typed Racket uses is in tests/typed-racket/random-real.rkt. I haven't settled on a general-purpose real number generator. For flonums I usually write something like this: #lang racket (require math/base

Re: [racket] error: degrees-complex: 360.0

2014-05-13 Thread Robby Findler
Thanks, Neil! Why is the loop needed? I can't seem to get it to take more than one iteration. Robby On Mon, May 12, 2014 at 11:24 PM, Neil Toronto neil.toro...@gmail.com wrote: He went with exact rationals. Here's another option, which preserves inexactness: (define (angle-proper-range

Re: [racket] error: degrees-complex: 360.0

2014-05-13 Thread Neil Toronto
I can't get it to take more than on iteration, either. It's there in case I missed something. :) Neil ⊥ On 05/13/2014 05:59 AM, Robby Findler wrote: Thanks, Neil! Why is the loop needed? I can't seem to get it to take more than one iteration. Robby On Mon, May 12, 2014 at 11:24 PM, Neil

Re: [racket] error: degrees-complex: 360.0

2014-05-13 Thread Robby Findler
Okay, then I'll go with this: (define/contract (angle-proper-range α) (- real? (between/c 0 360)) (let loop ([θ (- α (* 360 (floor (/ α 360]) (cond [(negative? θ) (+ θ 360)] [(= θ 360)(- θ 360)] [else θ]))) Can you point me to your random real number

[racket] error: degrees-complex: 360.0

2014-05-12 Thread Sean Kanaley
Hello all, I can't figure this out as I have no function called degrees-complex and it occurs only sometimes. It's always when rotating stuff through the positive x axis, as in it's probably related to floating point operations like sin or cos near 0 or perhaps integer multiples of 2pi. So far

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Danny Yoo
On Mon, May 12, 2014 at 4:11 PM, Sean Kanaley skana...@gmail.com wrote: Hello all, I can't figure this out as I have no function called degrees-complex and it occurs only sometimes. It's always when rotating stuff through the positive x axis, as in it's probably related to floating point

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Robby Findler
Hi Sean: do you have a program that demonstrates this error that you can share? That'll let me track down the bug. Hi Danny: The contracts are checked at the boundary based on the define/chk macro. This is an internal error somewhere -- angles are not restricted to being between 0 and 360. I

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Danny Yoo
Hi Danny: The contracts are checked at the boundary based on the define/chk macro. This is an internal error somewhere -- angles are not restricted to being between 0 and 360. I don't suppose you noticed how to make this error happen? Apologies; I didn't have time to investigate a good test

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Robby Findler
No no, not at all! Leads are also welcome. The obvious things I tried didn't signal an error. Robby On Mon, May 12, 2014 at 9:04 PM, Danny Yoo d...@hashcollision.org wrote: Hi Danny: The contracts are checked at the boundary based on the define/chk macro. This is an internal error somewhere

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Sean Kanaley
The entire program is too big but some tests: pass ... (rotate -0.0 SHIP) pass ... (rotate -0.0001 SHIP) fail... (rotate -0.0001 SHIP) Racket Users list: http://lists.racket-lang.org/users

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Robby Findler
Thanks! I've pushed a fix. Robby On Mon, May 12, 2014 at 9:19 PM, Sean Kanaley skana...@gmail.com wrote: The entire program is too big but some tests: pass ... (rotate -0.0 SHIP) pass ... (rotate -0.0001 SHIP) fail... (rotate -0.0001 SHIP)

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Danny Yoo
Wow. Floating point really is nasty. I see how it might have happened now. ;;; -0.0001 -1e-16 (+ 360 -1e-16) 360.0 ;;; Racket Users list: http://lists.racket-lang.org/users

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Robby Findler
Right. Probably there is a better fix, but the essential problem, as I understand it, is that there are more floating points between 0 and 1 than between any two other integers and the code made the assumption that that didn't happen The basic desire is to turn a real number into a number in

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Sean Kanaley
Interesting, my code has the same bug then. I called it modulo/real, used for things like displaying the space ship's rotation to the user or wrapping x coordinates to stay in the world. Apparently it's going to fail at some point with vector ref out of range. What was your fix? I was thinking

Re: [racket] error: degrees-complex: 360.0

2014-05-12 Thread Neil Toronto
He went with exact rationals. Here's another option, which preserves inexactness: (define (angle-proper-range α) (let loop ([θ (- α (* 360 (floor (/ α 360]) (cond [(negative? θ) (loop (+ θ 360))] [(= θ 360) (loop (- θ 360))] [else θ])))