Page 1 of 1 1
Topic Options
#156538 - 2006-02-03 12:04 AM Enhance CDbl to accept string representations of hexadecimal numbers
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
Hi All,

In order to avoid integer overflows by using val to convert large string representations of hexadecimal numbers, I suggest that CDbl should be enhanced to accept them. There are currently 3 UDF's that need to be utilised to process such hexadecimal numbers before you can pass the result into CDbl to get the decimal number. I have said before that I would prefer enhancements that deliver functionality that can't be realised by using UDF's but I believe that this is an exception.

While I'm at it, I would like to strongly suggest once more that COM event handling is also added.

Cheers,

Richard

Top
#156539 - 2006-02-03 12:42 AM Re: Enhance CDbl to accept string representations of hexadecimal numbers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Quote:

COM event handling




Think Microsoft is heading towards ".NET event handling"

Top
#156540 - 2006-02-03 01:08 AM Re: Enhance CDbl to accept string representations of hexadecimal numbers
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
Both would be good!
Top
#156541 - 2006-02-03 10:09 AM Re: Enhance CDbl to accept string representations of hexadecimal numbers
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
As you know you can already pass hex numbers directly:
Code:
; Biggest "positive" hex.
CDbl(&7FFFFFFF) ? ; = 2147483647

; Biggest hex that can be handled before things get screwy.
CDbl(&FFFFFF7F) ? ; = -129



The limit on the size of the hex number suggests that an integer conversion is taking place. This in turn implies that the conversion is done when the script is parsed, then the converted number is passed to CDbl().

KiXtart could be enhanced to convert hex numbers to double rather than int, but that would probably break many existing scripts. Perhaps an enhancement to support the "0x0" format of hex numbers which converted them internally to a larger data type could work.

I think that a general purpose built-in base converter function would be a better solution than enhancing CDbl().

The only problem with using doubles is that they are an approximation (I think that's the right word) of the number, which can lead to strange fractional parts appearing when you perform maths on them. However this is true of any use of data types which store the datum using similar methods, and is not just restricted to base conversion.

In the mean time, if you want to cut down on the number of UDFs required, this will do it for you:
Code:
udfHexToDBL("FFFFFFFFFFFFFFFF")

Function udfHexToDBL($s)
$udfHexToDBL=1.0
While $s<>""
$udfHexToDBL=$udfHexToDBL*Execute("Exit &"+Right($s,1))
$s=Left($s,-1)
Loop
EndFunction



The example results in "6.56840835571289E+018", which is a fair sized number.

Top
Page 1 of 1 1


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.15 seconds in which 0.086 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org