Re: Comments on Math_BaseX - was Re: [PEAR-DEV] Question about package.xml
| From: | Dave Mertens | Date: | Thu, 12 Dec 2002 20:09:27 +0000 |
| Subject: | Re: Comments on Math_BaseX - was Re: [PEAR-DEV] Question about package.xml | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-11587@lists.php.net to get a copy of this message | ||
On Wed, Dec 11, 2002 at 03:40:59PM -0800, Jesus M. Castagnetto wrote:
> Yep, I gathered that much from the code. What threw me off was that it was
> included in the Math_* namespace, which is why at first approach I was
> expecting to conform to base standard used in math where for the first 36 bases
> you use the alphanumeric charset, and from then on you are on your own ;-)
>
> Perhaps you can do both and support the normal mathematicl base char sets or
> random charsets.
For now it works like the way i intent it to work and is ready for implementing.
Support for strict mathematical base is maybe an option for version 2.
> For example, the method that initializes the valid set of chars you could
> accept 2 parameters, check if the first one is numeric or a string. If it is a
> string, then the user wants to use a non-standard charset base (like in your
> case), and then ignore the second parameter. If the first parameter is numeric,
> check if the second parameter is a string, which will mean the same as the
> previous case, with the addition that you can also check that the base and the
> number of chars in the string match. Finally, if the second parameter is not a
> string, ignore it and use the usual mathematical conventions, just making sure
> that 2 <= base <= 36.
Did you knew i had to read this part at least 3 times before i understood what you're
we're saying.
Drawing a diagram helpt me a lot ;-)
But seriously, it's sounds good. I'll keep it in mind designing the new version.
> Additionally, when a non-standard charset is being use, there should be a
> method that checks for uniqueness of all chars (count_chars() will here here).
This function is already inside the class. It loops the character string and does a substr_count for
each char.
It a char occurs more than once, an pear error is raised. There are also checks if the code passed
to toDecimal function are allowed,
is the base is set (Without a base, a conversion is impossible) and so..
> > I use this class to encode an ordernumber for use in an email. The user must
> > reply by visiting the link in the email.
> > We're using base13 (Only 13 characters from the alfabet).
> >
> > This class is indeed basicly doing the same as base_convert only with a
> > variable character set,
>
> I see. That is more akin to data encoding that numerical base transformation
> which has a definite meaning in math. Text_BaseEncoding might have been a more
> explicit moniker perhaps?
That's my my first methods were encode and decode. But toBase and toDecimal is also working for
me
But by passing a hex character set a strict mathematical conversion is also possible.
And because it based on the mathematical algorithm as the base conversion I categorized it as Math.
No-one objected so far on the namespace, and the next version will also do the normal mathematical
conversions.
But still advise people to use the normal PHP base_convert function in stead of using my class..
Tomorrow i will release the current package and tag the current branch. Than i can try to implement
the PHP base_convert for strict
mathematical conversion. The easiest way is just the substr (base length - 1) the part nessecary of
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", but than i would bypassing
the base_convert function. Something is wish to prevent. So i first have to work these things out
before i even start coding it ;-)
--
With best regards,
Dave Mertens - Senior Development Manager
dmertens@ism.nl
Innovative Solutions in Media
Schiekade 101
3033 BG Rotterdam, Netherlands
T +31-10-2436060
F +31-10-2436066
http://www.ism.nl
Quality Solutions - Reliable Partner