Not all devices are created equal

jschuchert

Active Member
Licensed User
Longtime User
I have 3 android devices: Nexus 7, Toshiba thrive and Archos arnova 7. My application is pretty much all math. In my post yesterday regarding floor and round, I have noticed that in at least one instance, the archos chokes at one of the lines of code, whereas the other 2 accept it fine. I ran into another one today where the archos failed while the others were good. With all of the devices out there, I wouldn't know where to start trying to devise work- arounds so all I can do is make a note in my documentation that there may be times when isolated calculations may not work on all tablets or phones. I would like to hear any comments or ideas from others who have had similar experiences.

I also found from yesterday's exchange that 'ceil' and 'round' don't yield the same results. Round was more accurate.

Jim S.
 

klaus

Expert
Licensed User
Longtime User
Could you be more clear on what you noticed.
I have noticed that in at least one instance, the archos chokes at one of the lines of code, whereas the other 2 accept it fine.
Ceil, Floor and Round are not the same.
Floor(4.4) = 4
Floor(4.6) = 4
Round(4.4) = 4
Round(4.6) = 5
Ceil(4.4) = 5
Ceil(4.6) = 5

Floor(-4.4) = -5
Floor(-4.6) = -5
Round(-4.4) = -4
Round(-4.6) = -5
Ceil(-4.4) = -4
Ceil(-4.6) = -4

Best regards.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Klaus,

Thanks for the clarification of ceil and round. I had not used ceil until yesterday when I found the discrepancy. I'll do some experimenting so I understand it better.

Regarding the device issue:

B4X:
Sub converttodms
   Dim deg,smin,sec,dega,mina,totmin,seca,totsec
   if main.dblbearingdms>=0 then
   deg=Floor(Main.dblbearingdms)
   dega=Main.dblbearingdms-deg
   Main.strdeg=deg
   End If
      
   totmin=dega*60
   smin=Floor(totmin)
   mina=totmin-smin
   
   Main.strmin=smin
   If Main.strmin=60 Then
   Main.strmin=00
     End If
     
   totsec=mina*60  
   sec=Round(totsec)    'this is where the archos crashes...others ok
   If sec=60 Then
   sec=00
   Main.strmin=Main.strmin+1
   If Main.strmin=60 Then 
   Main.strmin=00
   Main.strdeg=Main.strdeg+1
   End If
   End If
   Main.strsec=sec
  
If Main.dblbearing=90 OR Main.dblbearing=270 Then
Main.strdeg=90
End If
End Sub

The error says it is in the line with "sec=round(totsec)" java.lang.numberformat exception

Thanks for looking.
Jim S.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm afraid thea the problem is in your variable declaration.
You declare:
B4X:
Dim deg, smin, sec, dega, mina, totmin, seca, totsec
without specifying the type.
By default B4A admits undeclared variables of type String.
B4X:
sec=Round(totsec)
Returns a Double so Type conflict.
I think you need to be more precise in variable decleration.
Try with:
B4X:
Dim deg, smin, sec, dega, mina, totmin, seca, totsec As Double
or
B4X:
Dim deg, smin, sec, dega, mina, totmin, seca, totsec As Int
Best regards.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Klaus,

If that is the problem, why wouldn't that affect ALL of the devices rather than only 1? Nevertheless, I will try your suggestion for this particular issue.

Incidentally, the value noted below is the only one, so far, that causes the failure. Other similar values are ok.

If you want to test my code on your device try using
29.00000264324 as main.dblbearingdms

Thanks,
Jim S.
 
Upvote 0

jschuchert

Active Member
Licensed User
Longtime User
Klaus, when I made the type specifically "double" for 'sec', it worked on the archos!! Thank you so much for that insight for it never occurred to me. However, it still doesn't explain why the others were ok without it. Now I will go through the entire application and insure that the variable types are declared properly. That may take a while but will be worth it. Thanks again. :sign0142:
Jim S.
 
Upvote 0
Top