Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Detecting -0 and 0
- IssBjorn
-
New Scratcher
20 posts
Detecting -0 and 0
Currently I’ve got a script with divides coordinates of lines (lat,lon,lat,lon) into groups depending on the first number of the coordinates in each line (the first lat)
Examples of coordinates
0.546, 1.567, 0.647, 1.537,
0.674, etc, etc, etc,
-0.742, etc, etc, etc,
-0.653, etc,etc,etc,
1.546, etc,etc, etc,
1.452, etc etc etc,
What should be the result:
JsonData id=“00”>
0.546, 1.567, 0.647, 1.537
0.674,etc,etc,etc
</JsonData
JsonData id=“-0”>
-0.742, etc, etc, etc,
-0.653, etc,etc,etc
</JsonData
Etc
Etc
What I get
JsonData id=“00”>
0.546, 1.567, 0.647, 1.537
0.674,etc,etc,etc
-0.742, etc, etc, etc,
-0.653, etc,etc,etc
</JsonData
Etc
Etc
It should be separating the coords where it says -0 and 0. I’ve tried comparing the letters
if (letter 1 of thing1 = “-“ and letter 2 of thing1 = “0”) and (letter 1 of thing2 = “0”)
Set thingxml to (join (JsonData id =“ thing1)) join (”))
if list length > 1 (join thingxml /JsonData)
But it doesn’t seem to work. Sorry it’s in text, I had to quickly write it out cos of low battery.
Examples of coordinates
0.546, 1.567, 0.647, 1.537,
0.674, etc, etc, etc,
-0.742, etc, etc, etc,
-0.653, etc,etc,etc,
1.546, etc,etc, etc,
1.452, etc etc etc,
What should be the result:
JsonData id=“00”>
0.546, 1.567, 0.647, 1.537
0.674,etc,etc,etc
</JsonData
JsonData id=“-0”>
-0.742, etc, etc, etc,
-0.653, etc,etc,etc
</JsonData
Etc
Etc
What I get
JsonData id=“00”>
0.546, 1.567, 0.647, 1.537
0.674,etc,etc,etc
-0.742, etc, etc, etc,
-0.653, etc,etc,etc
</JsonData
Etc
Etc
It should be separating the coords where it says -0 and 0. I’ve tried comparing the letters
if (letter 1 of thing1 = “-“ and letter 2 of thing1 = “0”) and (letter 1 of thing2 = “0”)
Set thingxml to (join (JsonData id =“ thing1)) join (”))
if list length > 1 (join thingxml /JsonData)
But it doesn’t seem to work. Sorry it’s in text, I had to quickly write it out cos of low battery.
- ProgrammerDE
-
Scratcher
100+ posts
Detecting -0 and 0
I think what you want to do is group positive numbers and also group negative numbers.
You can calculate the sign of the number like this:
If the result is…
1: then the number is positive
-1: then the number is negative
NaN (Not a Number because you're dividing by 0): then the number is 0
You can calculate the sign of the number like this:
((number) / ([abs v] of (number)))abs(number) is the number but always positive
If the result is…
1: then the number is positive
-1: then the number is negative
NaN (Not a Number because you're dividing by 0): then the number is 0
- cwkaatmik9229
-
Scratcher
30 posts
Detecting -0 and 0
I think what you want to do is group positive numbers and also group negative numbers.isn't that just the sgn(x) function?
You can calculate the sign of the number like this:((number) / ([abs v] of (number)))abs(number) is the number but always positive
If the result is…
1: then the number is positive
-1: then the number is negative
NaN (Not a Number because you're dividing by 0): then the number is 0
- medians
-
Scratcher
1000+ posts
Detecting -0 and 0
I think what you want to do is group positive numbers and also group negative numbers.Or:
You can calculate the sign of the number like this:((number) / ([abs v] of (number)))abs(number) is the number but always positive
If the result is…
1: then the number is positive
-1: then the number is negative
NaN (Not a Number because you're dividing by 0): then the number is 0
(((number) / ([abs v] of (number))) + (0))Though doesn’t really work with -0 since thats 0
Last edited by medians (Dec. 24, 2022 04:49:22)
- IssBjorn
-
New Scratcher
20 posts
Detecting -0 and 0
I think what you want to do is group positive numbers and also group negative numbers.
You can calculate the sign of the number like this:((number) / ([abs v] of (number)))abs(number) is the number but always positive
If the result is…
1: then the number is positive
-1: then the number is negative
NaN (Not a Number because you're dividing by 0): then the number is 0
Forgive me but will this not work with telling the difference between 0 and -0 then? Those are the numbers I’m struggling with.
- IssBjorn
-
New Scratcher
20 posts
Detecting -0 and 0
maybe you want to show us the whole xml document
It’s not a full xml yet so it may or may not help but I’ll attach it shortly.
- IssBjorn
-
New Scratcher
20 posts
Detecting -0 and 0
maybe you want to show us the whole xml document
Ok turns out It was an error on my part the above code where I detect the letters does work, I just had it set to add the coordinates if thing 1 and thing 2 were different, obviosuly it didn't detect the the difference in the adding of the coords so the problem was it was adding the -1's before the <jsonData id=“-0” I added to that part of the code
If thing1 = thing2 and not letter 1 of thing2 = - and letter 2 of thing 2 =0 and letter 1 of thing 1 = 0
then add coords to list
<jsonData id=“0 0”>
0.06231307,51.4826202,0.06231307,51.4826202,
0.06231307,51.4826202,0.06320214,51.4864585,
0.06320214,51.4864585,0.06320214,51.4864585,
0.06320214,51.4864585,0.06320214,51.4864585,
0.06320214,51.4864585,0.06320214,51.4864585,
0.06320214,51.4864585,0.06044668,51.4937892,
0.06044668,51.4937892,0.06044668,51.4937892,
0.06044668,51.4937892,0.06420135,51.5004730,
0.06420135,51.5004730,0.06420135,51.5004730,
0.06420135,51.5004730,0.06420135,51.5004730,
0.06420135,51.5004730,0.07038384,51.5011729,
0.07038384,51.5011729,0.07038384,51.5011729,
0.07038384,51.5011729,0.08613377,51.4898429,
0.08613377,51.4898429,0.08613377,51.4898429,
0.08613377,51.4898429,0.08679854,51.4793161,
0.08679854,51.4793161,0.08679854,51.4793161,
0.08679854,51.4793161,0.10238628,51.4849665,
0.10238628,51.4849665,0.07563695,51.4620103,
0.07563695,51.4620103,0.07563695,51.4620103,
0.07563695,51.4620103,0.07836392,51.4583590,
0.07836392,51.4583590,0.07836392,51.4583590,
0.07836392,51.4583590,0.07304878,51.4520022,
0.07304878,51.4520022,0.07304878,51.4520022,
0.07304878,51.4520022,0.08068084,51.4506912,
0.08068084,51.4506912,0.08068084,51.4506912,
0.08068084,51.4506912,0.08906157,51.4513514,
0.08906157,51.4513514,0.09717232,51.4515808,
0.09717232,51.4515808,0.09717232,51.4515808,
0.09717232,51.4515808,0.11858255,51.4480810,
0.11858255,51.4480810,0.11858255,51.4480810,
0.11858255,51.4480810,0.12373759,51.4488726,
0.12373759,51.4488726,0.12373759,51.4488726,
0.12373759,51.4488726,0.13001262,51.4482322,
0.13001262,51.4482322,0.13001262,51.4482322,
0.13001262,51.4482322,0.13001262,51.4482322,
0.13001262,51.4482322,0.13001262,51.4482322,
0.13001262,51.4482322,0.13001262,51.4482322,
0.13001262,51.4482322,0.13001262,51.4482322,
0.13001262,51.4482322,0.13307746,51.4481983,
0.13307746,51.4481983,0.13307746,51.4481983,
0.13307746,51.4481983,0.13795950,51.4484061,
0.13795950,51.4484061,0.13795950,51.4484061,
0.13795950,51.4484061,0.13795950,51.4484061,
0.13795950,51.4484061,0.13795950,51.4484061,
0.13795950,51.4484061,0.14095796,51.4486016,
0.14095796,51.4486016,0.14095796,51.4486016,
0.14095796,51.4486016,0.14699494,51.4487821,
0.14699494,51.4487821,0.14699494,51.4487821,
0.14699494,51.4487821,0.15512974,51.4470944,
0.15512974,51.4470944,0.15512974,51.4470944,
0.15512974,51.4470944,0.15512974,51.4470944,
0.15512974,51.4470944,0.15512974,51.4470944,
0.15512974,51.4470944,0.15148043,51.4437300,
0.15148043,51.4437300,0.15148043,51.4437300,
0.15148043,51.4437300,0.15054702,51.4417648,
0.15054702,51.4417648,0.15054702,51.4417648,
0.15054702,51.4417648,0.15306184,51.4394127,
0.15306184,51.4394127,0.15306184,51.4394127,
0.15306184,51.4394127,0.16826134,51.4427761,
0.16826134,51.4427761,0.16826134,51.4427761,
0.16826134,51.4427761,0.17811267,51.4365432,
0.17811267,51.4365432,0.17811267,51.4365432,
0.17811267,51.4365432,0.19550235,51.4413523,
0.19550235,51.4413523,0.19550235,51.4413523,
0.19550235,51.4413523,0.19994216,51.4391267,
0.19994216,51.4391267,0.19994216,51.4391267,
0.19994216,51.4391267,0.21558112,51.4378166,
0.21558112,51.4378166,0.21558112,51.4378166,
0.21558112,51.4378166,0.22016828,51.4449279,
0.22016828,51.4449279,0.22016828,51.4449279,
0.22016828,51.4449279,0.21824933,51.4481163,
0.21824933,51.4481163,0.21824933,51.4481163,
0.21824933,51.4481163,0.20831602,51.4540490,
0.20831602,51.4540490,0.20831602,51.4540490,
0.20831602,51.4540490,0.20739594,51.4584205,
0.20739594,51.4584205,0.20739594,51.4584205,
0.20739594,51.4584205,0.23134228,51.4588737,
0.23134228,51.4588737,0.23134228,51.4588737,
0.23134228,51.4588737,0.23557816,51.4483625,
0.23557816,51.4483625,0.23557816,51.4483625,
0.23557816,51.4483625,0.23553969,51.4414580,
0.23553969,51.4414580,0.23553969,51.4414580,
0.23553969,51.4414580,0.24857112,51.4440675,
0.24857112,51.4440675,0.24857112,51.4440675,
0.24857112,51.4440675,0.24732213,51.4517517,
0.24732213,51.4517517,0.24732213,51.4517517,
0.24732213,51.4517517,0.26486470,51.4740613,
0.26486470,51.4740613,0.26486470,51.4740613,
0.26486470,51.4740613,0.26893101,51.5142840,
0.26893101,51.5142840,0.26893101,51.5142840,
0.26893101,51.5142840,0.28737447,51.5699587,
0.28737447,51.5699587,0.28737447,51.5699587,
0.28737447,51.5699587,0.25709141,51.6136375,
0.25709141,51.6136375,0.25709141,51.6136375,
0.25709141,51.6136375,0.18611622,51.6546663,
0.18611622,51.6546663,0.18611622,51.6546663,
0.18611622,51.6546663,0.14380236,51.7148085,
0.14380236,51.7148085,0.09387840,51.6908951,
0.09387840,51.6908951,0.09387840,51.6908951,
0.09387840,51.6908951,0.02941955,51.6786961,
0.02941955,51.6786961,0.02941955,51.6786961,
0.02941955,51.6786961,-0.0602958,51.6826414,
</jsonData><jsonData id=“-0”>
-0.0602958,51.6826414,-0.1052730,51.6909898,
-0.1052730,51.6909898,-0.1052730,51.6909898,
-0.1052730,51.6909898,-0.1452083,51.6888157,
-0.1452083,51.6888157,-0.1452083,51.6888157,
-0.1452083,51.6888157,-0.1862598,51.6850609,
-0.1862598,51.6850609,-0.1862598,51.6850609,
-0.1862598,51.6850609,-0.1923809,51.6861389,
-0.1923809,51.6861389,-0.1923809,51.6861389,
-0.1923809,51.6861389,-0.2046230,51.6847914,
-0.2046230,51.6847914,-0.2046230,51.6847914,
-0.2046230,51.6847914,-0.2208453,51.7118156,
-0.2208453,51.7118156,-0.2776052,51.7149748,
-0.2776052,51.7149748,-0.2776052,51.7149748,
-0.2776052,51.7149748,-0.2433064,51.7502497,
-0.2433064,51.7502497,-0.2197265,51.8183898,
-0.2197265,51.8183898,-0.2018737,51.9035339,
-0.2018737,51.9035339,-0.2247736,51.9164765,
-0.2247736,51.9164765,-0.1932329,51.9853399,
-0.1932329,51.9853399,-0.2730451,52.0852227,
-0.2730451,52.0852227,-0.3048706,52.1850585,
-0.3048706,52.1850585,-0.2462679,52.3205112,
-0.2462679,52.3205112,-0.2462679,52.3205112,
-0.2462679,52.3205112,-0.2462679,52.3205112,
-0.2462679,52.3205112,-0.2807682,52.4646674,
-0.2807682,52.4646674,-0.3222944,52.5345039,
-0.3222944,52.5345039,-0.3222944,52.5345039,
-0.3222944,52.5345039,-0.5765768,52.3937988,
-0.5765768,52.3937988,-0.7142009,52.3759796,
-0.7142009,52.3759796,-0.7710350,52.4119005,
-0.7710350,52.4119005,-1.0371812,52.3960750,
</jsonData><jsonData id=“-1”>
-1.0371812,52.3960750,-1.0532070,52.4076564,
-1.0532070,52.4076564,-1.0532070,52.4076564,
-1.0532070,52.4076564,-1.0532070,52.4076564,
-1.0532070,52.4076564,-1.0629696,52.4571283,
-1.0629696,52.4571283,-1.0629696,52.4571283,
-1.0629696,52.4571283,-1.0684204,52.5028411,
-1.0684204,52.5028411,-1.0684204,52.5028411,
-1.0684204,52.5028411,-1.0879107,52.5245255,
-1.0879107,52.5245255,-1.0879107,52.5245255,
-1.0879107,52.5245255,-1.1054992,52.5860595,
-1.1054992,52.5860595,-1.1054992,52.5860595,
-1.1054992,52.5860595,-1.0906088,52.6040201,
-1.0906088,52.6040201,-1.0906088,52.6040201,
-1.0906088,52.6040201,-1.0931396,52.6162719,
-1.0931396,52.6162719,-1.0931396,52.6162719,
-1.0931396,52.6162719,-1.1329650,52.6354980,
-1.1329650,52.6354980,-1.1329650,52.6354980,
-1.1329650,52.6354980,-1.1518853,52.6341247,
-1.1518853,52.6341247,-1.1518853,52.6341247,
-1.1518853,52.6341247,-1.1895985,52.6330801,
-1.1895985,52.6330801,-1.1895985,52.6330801,
-1.1895985,52.6330801,-1.1895985,52.6330801,
-1.1895985,52.6330801,-1.1895985,52.6330801,
-1.1895985,52.6330801,-1.2080671,52.6263655,
-1.2080671,52.6263655,-1.2080671,52.6263655,
-1.2080671,52.6263655,-1.2199159,52.6360758,
-1.2199159,52.6360758,-1.2199159,52.6360758,
-1.2199159,52.6360758,-1.1677812,52.6613486,
-1.1677812,52.6613486,-1.1677812,52.6613486,
-1.1677812,52.6613486,-1.1064557,52.6683341,
-1.1064557,52.6683341,-1.1064557,52.6683341,
-1.1064557,52.6683341,-1.0935196,52.6481408,
-1.0935196,52.6481408,-1.0935196,52.6481408,
-1.0935196,52.6481408,-1.0697937,52.6506042,
-1.0697937,52.6506042,-1.0697937,52.6506042,
-1.0697937,52.6506042,-1.1445794,52.5969674,
-1.1445794,52.5969674,-1.1445794,52.5969674,
-1.1445794,52.5969674,-1.1849612,52.5980412,
-1.1849612,52.5980412,-1.1849612,52.5980412,
-1.1849612,52.5980412,-1.2746676,52.6666891,
-1.2746676,52.6666891,-1.2746676,52.6666891,
-1.2746676,52.6666891,-1.2868452,52.6951131,
-1.2868452,52.6951131,-1.2868452,52.6951131,
-1.2868452,52.6951131,-1.2750954,52.7636019,
-1.2750954,52.7636019,-1.2750954,52.7636019,
-1.2750954,52.7636019,-1.3044066,52.8054961,
-1.3044066,52.8054961,-1.3044066,52.8054961,
-1.3044066,52.8054961,-1.3020154,52.9164134,
-1.3020154,52.9164134,-1.3020154,52.9164134,
-1.3020154,52.9164134,-1.2304687,52.9980468,
-1.2304687,52.9980468,-1.2304687,52.9980468,
-1.2304687,52.9980468,-1.2557605,53.0459683,
-1.2557605,53.0459683,-1.2557605,53.0459683,
-1.2557605,53.0459683,-1.3313346,53.1163155,
-1.3313346,53.1163155,-1.3313346,53.1163155,
-1.3313346,53.1163155,-1.3122782,53.1927602,
-1.3122782,53.1927602,-1.3122782,53.1927602,
-1.3122782,53.1927602,-1.3305245,53.2418995,
-1.3305245,53.2418995,-1.3305245,53.2418995,
-1.3305245,53.2418995,-1.3150482,53.2598063,
-1.3150482,53.2598063,-1.3150482,53.2598063,
-1.3150482,53.2598063,-1.2762818,53.3226380,
-1.2762818,53.3226380,-1.2762818,53.3226380,
-1.2762818,53.3226380,-1.2875354,53.3350667,
- Oumuamua
-
Scratcher
1000+ posts
Detecting -0 and 0
OK, and what is that you want to do with such data? Why the sign “minus” is a problem?
- IssBjorn
-
New Scratcher
20 posts
Detecting -0 and 0
OK, and what is that you want to do with such data? Why the sign “minus” is a problem?
The minus sign wasn’t the problem it was detecting -0 or 0, obviously both are just 0 so I had to detect the characters instead. I had no problem detecting -1 and say 1 as they are not equal like -0 and 0 are.
- Oumuamua
-
Scratcher
1000+ posts
Detecting -0 and 0
Hi, just go to https://scratch.mit.edu/projects/781363066/editor/ and see if it is that what you want to achieve; I've kept identifiers with this format: “0 0”
- IssBjorn
-
New Scratcher
20 posts
Detecting -0 and 0
Hi, just go to https://scratch.mit.edu/projects/781363066/editor/ and see if it is that what you want to achieve; I've kept identifiers with this format: “0 0”
Thankyou i've figured it out
- Oumuamua
-
Scratcher
1000+ posts
Detecting -0 and 0
OK, no problem 
I wish you, and everybody, an happy new year

I wish you, and everybody, an happy new year

- LittleGreyCells
-
Scratch Team
1000+ posts
Detecting -0 and 0
Glad you found an answer! Since this is resolved, I'll close it to help highlight the answer and prevent future responses. If you need it re-opened, though, you can report this and ask. 

- Discussion Forums
- » Help with Scripts
-
» Detecting -0 and 0