Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22553
| From | Tim Streater <timstreater@greenbee.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: My code find negative squares buggy? |
| Date | 2014-01-10 16:19 +0000 |
| Message-ID | <100120141619527449%timstreater@greenbee.net> (permalink) |
| References | <ed1316d2-3b87-4a4a-901a-05f6131e3e4f@googlegroups.com> <100120141552439734%timstreater@greenbee.net> <d1e23965-ac9e-4bd7-9d3d-3af30643f383@googlegroups.com> |
In article <d1e23965-ac9e-4bd7-9d3d-3af30643f383@googlegroups.com>,
<jonas.thornvall@gmail.com> wrote:
> Den fredagen den 10:e januari 2014 kl. 16:52:43 UTC+1 skrev Tim Streater:
> > In article <ed1316d2-3b87-4a4a-901a-05f6131e3e4f@googlegroups.com>,
> >
> > <jonas.thornvall@gmail.com> wrote:
> > > This works fine
> > > square=Math.sqrt(number,2);
> > > if(square-Math.floor(square)== 0){ctx.fillStyle = 'red';}
> > > This does not?
> > > negsquare=Math.sqrt(-number,2);
> > What does negsquare get set to?
> > > if(number<0 && negsquare-Math.floor(negsquare)== 0) {ctx.fillStyle =
> > > 'orange';}
> > And what does Math.floor do with whatever negsquare got set to above?
> If number is -50
> negsquare=Math.sqrt(-50,2);
But suppose number is +50. What does your code do then?
> negsquare=7,0710678118654752440084436210485
>
> Or? Isnt't sqrt=Math.sqrt(number,2); equivalent with
> negsqrt=Math.sqrt(-number,2); given that number is negative?
>
> Which gives
>
> if(-50<0 && 7,0710678118654752440084436210485-Math.floor(7,0710678118654752440084436210485
> )== 0) {ctx.fillStyle ='orange';}
>
> At least that is what i though it would do?
I expect you need to check operator precedence in your "if".
--
Tim
"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
My code find negative squares buggy? jonas.thornvall@gmail.com - 2014-01-10 07:40 -0800
Re: My code find negative squares buggy? jonas.thornvall@gmail.com - 2014-01-10 07:44 -0800
Re: My code find negative squares buggy? Tim Streater <timstreater@greenbee.net> - 2014-01-10 15:52 +0000
Re: My code find negative squares buggy? jonas.thornvall@gmail.com - 2014-01-10 08:09 -0800
Re: My code find negative squares buggy? Tim Streater <timstreater@greenbee.net> - 2014-01-10 16:19 +0000
Re: My code find negative squares buggy? jonas.thornvall@gmail.com - 2014-01-10 08:32 -0800
Re: My code find negative squares buggy? Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-10 17:58 +0100
csiph-web