Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Basic4ppc Wishlist > Bug Reports
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Bug Reports Post about errors or bugs encountered.

Numeric conversion limitation?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-06-2007, 03:44 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default Numeric conversion limitation?

I'm having trouble displaying large numbers using the built in data types. Decimals and int64 both appear to be limited to 15 bit decimal precision when converted to strings. It looks suspiciously like the internal numeric conversions are limited to this precision. Is this so?

The decimal.dll components (which are a wrapper to system.decimal) work just as I expect, as they have their own string conversion routine, except that I can't put them in arrays.
Reply With Quote
  #2 (permalink)  
Old 07-06-2007, 03:57 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,714
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

By design, Basic4ppc uses 16 bit for floating point numbers.
You should the use Decimal library for higher precision (it uses 128 bits).
You could create a pseudo array using AddObject and Control keyword.
Something like:
Code:
for i = 0 to 49
 AddObject(
"dec" & i, "Decimal")
 Control(
"dec" & i).New1
Next
Reply With Quote
  #3 (permalink)  
Old 07-06-2007, 04:17 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Erel View Post
By design, Basic4ppc uses 16 bit for floating point numbers.
Sorry Erel but I don't understand your reply. I am obviously getting far higher precision than 16 bit floating point on Decimals - stated to be 96 bits in the help and Int64s - stated to be 64 bits in your help. And I suspect that internally the arithematic is correct but when I display them in a text box or convert them to a string using Format then both are limited to 15 decimal places of precision - as though the string conversion routines cannot cope with more places.

For example the highest number I can get an Int64 or Decimal to display correctly is 999999999999999 (15 places if I've type correctly) and an Int64 isn't a floating point type (nor I thought were Decimals - they may have exponents but should not be susceptible to the rounding problems that afflict floating point types)
Reply With Quote
  #4 (permalink)  
Old 07-06-2007, 04:47 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,714
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Sorry but it is of course not 16 bits. Basic4ppc uses 64 bit for all numbers (System.Double).
This is enough for most applications.
If you need higher precision you could use the Decimal library (which uses 128 bits).
This example will show 1/7 with 25 decimal digits.
Don't forget to add the Decimal library.
Code:
<font size="2"><font color="#008000">'Add a DecOperator named dec.
</font></font><font size="2"><font color="#0000ff">Sub </font></font><font size="2">Globals
</font><font size=
"2"><font color="#0000ff">End Sub
</font></font><font size=
"2"><font color="#0000ff"
Sub </font></font><font size="2">App_Start
 dec.New1
</font><font size=
"2"><font color="#0000ff"> AddObject</font></font><font size="2">("d1","decNumber")
</font><font size=
"2"><font color="#0000ff"> AddObject</font></font><font size="2">("d2","decNumber")
 d1.New1
 d2.New1
 d1.Value = dec.ParseD(
"1")
 d2.Value = dec.FromDouble(
7)
 d1.Value = dec.DivD(d1.Value,d2.Value)
 d1.Value = dec.AddD(d1.Value, d2.Value)
</font><font size=
"2"><font color="#0000ff"msgbox</font></font><font size="2">(d1.ToString2("n25"))
</font><font size=
"2"><font color="#0000ff">End Sub
</font></font>
Reply With Quote
  #5 (permalink)  
Old 07-06-2007, 05:06 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Hi Erel

I was composing the following when your second reply came in. I understand what is happening but I think that your help needs clarification.

Reply was going to be
---------------------

I think there is a misunderstanding here (and a typo in your reply above).

From help on Variables" - "All simple variables are variant variables. Which means that any variable can store any type of number or a string"

My emphasis on "any"

I took this to mean that they were Visual Basic type variants and could take the datatypes specified in help on "Data types"

Name Description Range
· Byte 8-bit unsigned integer 0 - 255
· Int16 16-bit signed integer -32768 - 32767
etc.


However poking around with Reflector it seems that you have only two types internally, strings and doubles (i.e 64 bit floating point and not 16 bit as you replied). Even the arrays of the other datatypes appear to be arrays of double. So I assume that the other data types are produced solely for interface purposes and are never visible internally, which raises the question of what happens if an external library returns a number out of range of a double!
Reply With Quote
  #6 (permalink)  
Old 07-06-2007, 05:08 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by Erel View Post
If you need higher precision you could use the Decimal library (which uses 128 bits)
Yes I 've already played with that and found it satisfactory
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiline textbox size limitation? Cableguy Questions (Windows Mobile) 9 09-26-2008 08:13 PM
How Is This Conversion An Error? Louis Bug Reports 3 11-20-2007 08:02 AM
GPS and Conversion forisco Questions (Windows Mobile) 6 11-13-2007 09:29 PM
Numeric Data Input Mask? david Questions (Windows Mobile) 3 11-03-2007 03:04 PM
Conversion and trig functs bdiscount Additional Libraries 0 10-08-2007 03:55 PM


All times are GMT. The time now is 03:46 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0