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

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

Basic4ppc Wishlist Missing any feature?

VAL keyword

Reply
 
LinkBack Thread Tools Display Modes
  #21 (permalink)  
Old 09-11-2010, 06:48 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Attached a small test program with a Val function that does the following:
- accepts the characters 0 - 9 - + E e . , blank space tab cr lf
- these characters are stripped , blank space tab cr lf (+)
- leading zeros removed
- non relevant ending characters removed E e + - 0

- &0 (for octal) and &H (for hexadecimal), as in the original function, are not supported.

Best regards.
Attached Files
File Type: sbp TestValFunction.sbp (3.2 KB, 7 views)
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide

Last edited by klaus : 09-12-2010 at 06:47 AM.
Reply With Quote
  #22 (permalink)  
Old 09-16-2010, 08:24 AM
Basic4ppc Veteran
 
Join Date: Apr 2007
Posts: 269
Default

Way of topic, but I have fond memories of coding in assembler, pushing and popping around and using the good old accumulator....
regards,
Marc
Reply With Quote
  #23 (permalink)  
Old 09-16-2010, 09:10 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 810
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by klaus View Post
Attached a small test program with a Val function that does the following:
- accepts the characters 0 - 9 - + E e . , blank space tab cr lf...
In a reply (http://www.basic4ppc.com/forum/offic...html#post37134) to a query from me, Andrew Graham refers to the number formatting options that are available in Basic4PPC over and above those listed in the help for Format().

I note that they (may) include:
Round-trip
This format is supported only for the Single and Double types. The round-trip specifier guarantees that a numeric value converted to a string will be parsed back into the same numeric value.
That sounds rather relevant for automatic conversions such as applied by Basic4PPC.

However I still have to determine why an expression I have written in my code with "(...) Mod 360" can still yield the result "360", both under desktop IDE and when compiled! ("360" is not a valid compass bearing, just as 24:00 is not a valid 24-hour clock time.)

Mike.
Reply With Quote
  #24 (permalink)  
Old 09-16-2010, 10:55 AM
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 mjcoon View Post
why an expression I have written in my code with "(...) Mod 360" can still yield the result "360
I'd like to see the expression and the input string values to it that give a "360" result but my guess is that it is a classic manifestation of the inherent inability of floating point to exactly represent a number. All arithmetic operations in Basic4ppc are carried with double floating point values, even though the operations may look like integer operations and I would guess that the actual theoretical value would be a smidgin less than 360 and gets rounded because floating point cannot exactly represent it. This is why banks use exact representational value types, like Decimal in C#, for currency calculations and not floating point.

For example

a = Int( "359.9999999999999")
b = Int(359.9999999999999)

produces a value of 360 for b, not 359 as you might expect. In this case the string is passed through by Basic4ppc to the final code but the literal is converted to the value of 360 before being emitted. Why the difference in treatment of what are essentially two identical strings I don't know but it looks like a floating point effect to me.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #25 (permalink)  
Old 09-16-2010, 11:47 AM
Basic4ppc Expert
 
Join Date: May 2008
Location: Berkshire, UK
Posts: 810
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by agraham View Post
... because floating point cannot exactly represent it.
At some point in my 40 years in IT I became aware that decimal fractions cannot all be represented exactly as binary fractions in floating point. But that there should be no problem with integers.

Which is why I thought that my "(...) Mod 360" should be OK because 360 is an integer.

I'm afraid I cannot now reproduce the problem. (I had already made it go away by tweaking the (...) expression.)

On the other hand my problem may, rather trivially, have been a result of rounding after the Mod 360. If the result was close to 360 within the representational limit (I only show bearings to one decimal digit, and that is really too fine) then it would be rounded up. Had I happened to see a value very close to 360 in the IDE then I might have twigged what was happening.

As it is, I should round to appropriate accuracy first, then test for rounding up to 360, and then just set the answer to zero! Testing for > 359.9 should give a similar effect, but could fall into the floating point problem that we have been discussing.

Mike.
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
Today keyword? JesseW Basic4ppc Wishlist 3 03-21-2009 10:26 AM
find keyword lijingtong Questions (Windows Mobile) 2 06-20-2008 09:05 AM
Auto Keyword im4retro Questions (Windows Mobile) 2 06-06-2008 03:45 PM
Comment after Do keyword Erel Bug Reports 1 07-24-2007 08:33 PM
filesearch keyword Cableguy Questions (Windows Mobile) 6 05-16-2007 05:44 PM


All times are GMT. The time now is 01:55 PM.


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