# How do I explain this inconsistency ?

Get help using Construct 2

### » Wed May 03, 2017 2:26 pm

Message: Semoreh can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hi there !

I'm no big connoisseur in trigonometry but I had to dip into it a little in order to generate a laser for my Run N' Gun shooter. I've managed to have my laser working but I've been puzzled by one small inconsistency I can't explain...

(I've simplified the CapX and you can download it here : https://www.mediafire.com/?hbpi2gy8icdcjhc)
(to generate a laser you have to hold an arrow or more and use the left click)

See, I have a debug box. When I add into my debug box Cos(270) it writes 0 as expected. Also Sin(270) writes -1.
So that's good.
But when I try to concatenate Cos(270)&" / "&Sin(270) the cosinus is wrong. It gives a figure veeeeery small but not nul. So it writes something like "-1.8369701987210297e-16 // -1" instead of "0 // -1".

Is it because of the cosinus ?
Or because of the concatenation ?
More importantly, can this mess up my computation for the laser's width in any way ? (line 27-28 of the Event Sheet 1)

Thanks in advance for taking the time to reassure me
Best regards
Last edited by Semoreh on Wed May 03, 2017 2:40 pm, edited 1 time in total.
B
6
Posts: 43
Reputation: 347

### » Wed May 03, 2017 2:35 pm

Why are you using strings for math?
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

### » Wed May 03, 2017 2:39 pm

What do you mean ?
I can usually concatenate figures without problem
B
6
Posts: 43
Reputation: 347

### » Wed May 03, 2017 2:51 pm

Well to start it's an extra step to convert strings into numbers, and then there's bound to be issues with the conversion, which could vary widely between browsers.
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

### » Wed May 03, 2017 2:57 pm

I'm converting a number into a string, sure, but that doesn't explain why Cos(270°) becomes this weird number when it's not alone. 0 converted into a string should still be "0", right ?
Cos(270°) should always be strictly equal to zero... unless I don't understand cosinuses well (which is a possibility).
B
6
Posts: 43
Reputation: 347

### » Wed May 03, 2017 3:27 pm

Could be 0, could be null.
It depends on the browser, and how it's setup to handle it.
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

### » Wed May 03, 2017 4:49 pm

That's the problem with floating point arithmetic. There's nothing you can do about it, you just have to deal with it. However, a number like -1.8369701987210297e-16 is so small that you won't ever notice anything visually... so you might as well consider it to be 0.
B
81
S
33
G
27
Posts: 1,029
Reputation: 21,143

### » Wed May 03, 2017 5:19 pm

Yeah, the value is the real issue.
Sorry I'm just off on the strings.
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

### » Wed May 03, 2017 7:08 pm

If you want to force the debug text to be more readable, I guess you could always do something like rounding the value to 5 or 6 decimals (or whatever number you deem significant).

example for 5 decimals :

Smaller values will then always be equal to 0.
B
81
S
33
G
27
Posts: 1,029
Reputation: 21,143

### » Wed May 03, 2017 7:37 pm

Oh, it's just text.
Well, nevermind all I said.
B
179
S
50
G
207
Posts: 8,719
Reputation: 128,306

Next

### Who is online

Users browsing this forum: No registered users and 10 guests