This code (2 lines of diagnosis hacks + 1 original problem line):
is producing this error when the string is "-0":
I tried some parsing test code at the start of the same program:
but it seems to work just fine on the offending "-0" (indeed: better than fine, since it looks like it implements the IEEE signed-zero nuance):
Having mentioned the signed-zero nuance, perhaps I should tug on that loose thread a little harder.
But still, why would the same casting work in one case, fail in another? Especially when IsNumber says the string is ok.
B4X:
Dim TempString As String = lblReading.Text
Log("len = " & TempString.Length & ", str = [" & TempString & "] isnum = " & IsNumber(TempString))
Dim CurrentReading As Float = TempString '''lblReading.Text
len = 2, str = [-0] isnum = true
Error occurred on line: 423 (Main)
Cannot parse: -0
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
PTOC -[B4I ObjectToNumber:] + 464
PTOC -[B4IRDebugUtils numberCast::] + 268
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
PTOC +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1624
PTOC -[B4IShell runMethod:] + 448
PTOC -[B4IShell raiseEventImpl:method:args::] + 1640
PTOC -[B4IShellBI raiseEvent:eventarams:] + 1372
PTOC __24-[B4ITimer startTicking]_block_invoke + 332
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 412
libdispatch.dylib <redacted> + 1308
libdispatch.dylib <redacted> + 784
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1924
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 104
UIKitCore UIApplicationMain + 212
PTOC main + 124
libdyld.dylib <redacted> + 4
)
I tried some parsing test code at the start of the same program:
B4X:
Private Sub Application_Start (Nav As NavigationController)
'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
Dim TestString As String
Dim TestFloat As Float
TestString = "1.23"
TestFloat = TestString
Log(TestString & " = " & TestFloat)
TestString = "-1.23"
TestFloat = TestString
Log(TestString & " = " & TestFloat)
TestString = "0"
TestFloat = TestString
Log(TestString & " = " & TestFloat)
TestString = "+0"
TestFloat = TestString
Log(TestString & " = " & TestFloat)
TestString = "-0"
TestFloat = TestString
Log(TestString & " = " & TestFloat)
Application_Start
1.23 = 1.2300000190734863
-1.23 = -1.2300000190734863
0 = 0
+0 = 0
-0 = -0
Application_Active
Having mentioned the signed-zero nuance, perhaps I should tug on that loose thread a little harder.
But still, why would the same casting work in one case, fail in another? Especially when IsNumber says the string is ok.