Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 01:18 05 Feb 2023 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : datatype of CTRLVAL() if numeric ?

Author Message
ville56
Newbie

Joined: 08/06/2022
Location: Austria
Posts: 36
Posted: 08:05pm 19 Jan 2023
Copy link to clipboard 
Print this post

2nd try, now in the proper forum ....    mea culpa, mea maxima culpa!

I'm trying to read a float value from a NUMBERBOX via the CTRLVAL() statement. If i enter 89.9 in the numberbox, a PRINT CTRLVAL() returns 89.90000153.
This seems to be in contrast to an assignment like i=val("89.9"), i being declared as float datatype, which gives 89.9 on "print i".

Is there a lower (single?) precision for the internal representation/conversion of CTRLVAL than for normal float variables or do i something wrong ?

Any clarification is welcome

Regards, Gerald
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5119
Posted: 08:44pm 19 Jan 2023
Copy link to clipboard 
Print this post

That's floating point (IEEE 754) for you.

PRINT STR$(....) will display it in whatever resolution you desire.
You have to take precautions if you are checking for equality.

Jim
VK7JH
MMedit   MMBasic Help
 
ville56
Newbie

Joined: 08/06/2022
Location: Austria
Posts: 36
Posted: 09:22am 20 Jan 2023
Copy link to clipboard 
Print this post

Thanks for the info about float format, Jim. But there ist still something strange for me.

I've tried the following:

dim float i
i=89.9
print i
  Result is: 89.9 and what i expected it to be.

--- but ---

'gui components are defined somewhere upfront
ctrlval(#1)=89.9
print ctrlval(#1)
  Result is: 89.90000153 this seems like 32 bit representation ... unusable for my problem. Same behavior if you enter the number via the touchpad.

So there is appearantly some inherent difference in assigning a numeric value to a 'normal' float variable and the assignment of the value to the ctrlval() command. Variables seem to be 64 bit, ctrlval() assignments seem to be 32 bit, be it direct assignment as in my example or assignment via the touch entry.
What i want to know is, is there a way to have 64 bit resolution for touch input of float numbers, or why there is currently no 64 bit resolution for that.

Thanks, Gerald
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 3327
Posted: 10:01am 20 Jan 2023
Copy link to clipboard 
Print this post

Nasty, unpredictable things, floats. Do everything in integers and just multiply/divide them by powers of 10. ;) Better still, do everything in binary or, if you must, HEX. :)

>**** ERROR *** REBOOT UNIVERSE TO CONTINUE ***


More seriously, I rather suspect that the GUI commands might be taken pretty much as they are from the 32-bit MMBasic systems. They may not handle 64-bit values properly and could be ignoring the upper bits. I've not used them much so I can't offer any practical experience.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 2930
Posted: 10:07am 20 Jan 2023
Copy link to clipboard 
Print this post

  Mixtel90 said  >**** ERROR *** REBOOT UNIVERSE TO CONTINUE ***


More like "Click [OK] to reboot universe" and then not show any buttons ... or worse yet not show a [Cancel] button.

Best wishes,

Tom
CMM2 Welcome Tape, Creaky old text adventures
 
ville56
Newbie

Joined: 08/06/2022
Location: Austria
Posts: 36
Posted: 10:53am 20 Jan 2023
Copy link to clipboard 
Print this post

hmmm ... seems to be a break in the floating point arithmetics architecture of MMBasic on the pico.

I'm not a big fan of floating arithmetics anyway, do whatever i can in integer. Had a lot of "bad" experiance with rounding errors in my 'industrial' live, long time ago, programming realtime process control. Later in my 'banking' live, integers where almost the only way to do it.

So i have to revert to integers, or maybe strings...

Reset Universe?
     O Yes
     O No
     X Not sure

Thanks to all, Gerald
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 6828
Posted: 11:56am 20 Jan 2023
Copy link to clipboard 
Print this post

The PicoMite uses floats for GUI operations to save memory - 16 bytes per control. I'll change the formatting to fix the issue in the next 5.07.07 beta
 
ville56
Newbie

Joined: 08/06/2022
Location: Austria
Posts: 36
Posted: 02:38pm 20 Jan 2023
Copy link to clipboard 
Print this post

Peter, thank you. This will make things easier for me.

Regards, Gerald
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 6828
Posted: 03:05pm 20 Jan 2023
Copy link to clipboard 
Print this post

Please check V5.07.07b7 just posted to see if it works - thanks
 
ville56
Newbie

Joined: 08/06/2022
Location: Austria
Posts: 36
Posted: 04:23pm 20 Jan 2023
Copy link to clipboard 
Print this post

Just tried V5.07.07b7, no change in behavior.

Regards, Gerald
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 6828
Posted: 04:52pm 20 Jan 2023
Copy link to clipboard 
Print this post

Can you post your program or a simple demo program so I can test
Edited 2023-01-21 02:54 by matherp
 
ville56
Newbie

Joined: 08/06/2022
Location: Austria
Posts: 36
Posted: 07:48pm 20 Jan 2023
Copy link to clipboard 
Print this post

created 2 progs

- gui-1.bas shows the difference between storing a value in a float variable vs ctrlval() which should behave the same. A typical value where the difference shows up is 89.9

- gui-2.bas lets you enter a value into a numberbox and prints it. If you enter 89.9 you get the same difference as shown in gui-1.bas

Both examples point, in my opinion, to differences in the internal representation of floating point numbers (variable vs. gui subsystem)


guitest.zip

Hope this shows what my problem is.

Reagrds, Gerald
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2023