2
Solved

maths adding negative number

Yesterday (or possibly one or two days before, I had tasker turned of for a while) one of my tasks that have been working for years started chrashing. After some debugging I've isolated the error to a 'set variable' where I add two other variables using 'do maths'. The problem occurs when the second of the variables added is negative. Trying to replicate the errror I found that if i just tried to set %newvar to e. g. 3+-1 there's no problem, but if i first set %var to e. g. 0-1 (getting a negative result) and the try to set %newvar to 3+%var then it crashes with an error message saying "Mathematical expression contains the invalid value - 1". (There seems to have been an update to the 'do maths' functionality at about the same time this started happening, as there is now a 'max rounding digits' alternative that I don't remember seeing before) 

7 replies

A

Now it seems to have started working again (and my minimal example no longer produces an error either). Hope it lasts! 

A

... and now the issue is back again. I'll see if I can get it to go away by restarting or something, but even if it is temporarily fixable it's still a problem if it can start happening again at random(?) times. 

A

Restarting worked, but as I said below this still means that my tasks aren't reliable :(

Even though I'm not sure how, the on-again off-again nature of this problem makes me think that it might be related to an issue I had a few years back after the android update that introduced locales. The locale in tasker kept switching back and forth between the internal one tasker 'wanted' and the one I have on the rest of my phone (Swedish). I never managed to really fix that, I just added a formatting step (using AutoTools) in every task that used dates or weekdays from built-in global variables so that they worked reagardless of which format the date/weekday was in originally. So maybe the issue I'm having now is appearing and dissapearing because it happens with one of the locales but not the other? I'll try to do some troubleshooting to see if this is the case, but since I haven't found any way to control the switches it will probably take a while. 

A

Ok, sorry for the barrage of comments here... I realized I could simulate the locale switches by just changing the locale on the whole phone (which shouldn't affect the locale in tasker if I remember correctly but still does). I was right, the problem occurs when the locale is set to swedish but not when it is set to english. Which presumably means that when the internal locale in tasker manages to override the one on the rest of the phone (as it should) things work fine, but when the phone locale gets the upper hand then the issue reappears. Note though that the locale switches have been happening for a few years now and this problem only occured a few weeks ago, in tasks that had been working fine until then and hadn't been changed.

In case it matters, I have a Sony Xperia XZ1 compact (G8441) with android  version 9 (pie?). (But as I said the locale changes have been happening ever since locales where introduced in android, and I'm pretty sure I've switched phone at least once since then, though they have all been different Sony Xperia compact models) 

Hi. Thanks for the info! So, to confirm, if the phone's locale is in english this never occurs?

A

Just to give an update on this: I've had my locale switched to English since to avoid this problem since it started appearing (which was apparently about 7 months ago since thats when I posted the question). I haven't had any issues with this during that time, but when I tried switching back to Swedish now the problem returned. It definitely looks like the minus sign is slightly longer with the swedish locale, so I suspect that the issue might be caused by the swedish locale using another symbol for the minus sign. 

A

It doesn't seem like that. I switched to english after I found that it seemed to solve it and I haven't noticed it happening since then. (but of course that means that everything else is in english now, which is irritating) And when I switched back and forth between swedish and english it made the test task I'd made start and stop working. It looks a little bit like maybe the minus sign looks a bit different when the problem happens, but I can't say for sure since I can't see them at the same time. 

K

I also have this issue and what is interesting is that I am also a Swedish user. Unfortunately, this my task does not always fail when a negative number is added to another variable so I can't reproduce this issue consistently. This is true regardless of which locale I use. Perhaps this issue is caused by that fact that the Swedish locale is in the list of supported locales in the system at all? My languages are in the following order:

  1. English (UK)
  2. English (US)
  3. Swedish

I agree with Aase's view that the minus sign is slightly longer than it is any other application. I guess it is another UTF8-symbol? Please see the below screenshot:

In my case. the numbers I try to add are both created by the Set Variable action using "do maths"- Is it possible that the version that added the max rounding digits introduced any changes that could have caused this?

Please let me know if I can help investigate this issue in any way. I assume an exception is thrown when this happen? Can I catch that somehow?

Thanks

Does the same thing happen if you try to do:

7.7+(-0.167)

?

K

@João

7.7+(-0.167) works fine if I type the minus sign directly from the Android keyboard. However, I tried setting my variable as follows:

%tolog = %WORKHOURS + (%offset)

which didn't work if %offset was negative and set using the Variable Set action with Do Maths marked. If I set %offset to a negative value manually, it works fine.

I did some investigations on the minus characters by copying the error from Tasker and getting the unicode of the minus character. As it turns out, the minus character in the error in Tasker is not the same as the minus character (hyphen) I can type using the Android keyboard. Here are the unicodes of the characters:

− (the one in the Tasker error): U+2212

- (the working one): U+002D

While I can't know if the actual character is the underlying issue, it does seem to be related due to the error provided by Tasker. It fails at the character with offset 4, which is the '−' character, assuming the offset is one-indexed.

If it helps, please find a simple Java unit test below that prints the unicodes of the characters. The test of course fails due to the characters not being the same.

@Test
public void testMinusSignsAreEqual() {
        final char notWorkingSign = '−';
        final char workingSign = '-';
        System.out.println(notWorkingSign + " : " + Integer.toHexString(notWorkingSign));
        System.out.println(workingSign + " : " + Integer.toHexString(workingSign));
        Assert.assertEquals(String.valueOf(workingSign), String.valueOf(notWorkingSign));
}

Please let me know if I can provide any additional details.

Thanks

Thank you very much, that was super helpful! :)

I think I may have fixed it. Can you please try this version? https://drive.google.com/file/d/1MHWlVLGfwJmMRWRKlhFSFl5vCgOah3Ew/view?usp=sharing

Indeed it could have something to do with the rounding numbers, because I'm using a different string formatter than before to output the final result.

Thanks again!

K

I triggered the error this afternoon and then immediately downloaded the new apk and re-ran the same task with the same data and it seems to work :) I will let you know if the issue reappears!

Thank you very much for fixing this! Helpful as always!

Awesome! :) Glad this is fixed!

Topic is closed for comments