On Wed, Jan 26, 2005 at 12:06:15PM +0100, Pailloncy Jean-Gerard wrote: > If I have a column with "speed DOUBLE(m1s-1)" > I want to be able to put in in any unit format. > If I want special output, I would have a function > doubleunit_to_char(speed,'si') that will output "3 m/s" and > doubleunit_to_char(speed,'si','fr') that will output "3 mètre/seconde" > and > doubleunit_to_char(speed,'si','en') that will output "3 meter/second" > and > doubleunit_to_char(speed,'british','en') that will output "xxx > yard/day" ;-) Sound very cool. Don't forget en_AU should return "metre" and en_US should return "meter". Not to mention "rods/hogshead" :) > I am in the process of writing such function to convert from test to an > internal format. > But the problem is that all the work I am doing is about coupound type > (double, unit) > the unit type is an integer with for table for the definition of unit, > convertion and translation in human form. I just thought though, it's going to be impossible to list all possible unit types in a table. There are essentially infinite of them. For example, the gravitational constant is m3 kg-1 s-2, Plancks constant is m2 kg s-1, none of which appear in the standard list of derived units. Unfortunatly, the only bolution I can think of is to encode the units as numbers in a bitfield. There's only seven base units anyway so if you allocate 4 bits for each you can fit it all in 32 bits. If you wanted more units you could cut the usage of mol and cd to two bits since they don't really need powers from +7 to -8. You still need the table to do lookups for input and output but it is a little more flexible. Any chance of seeing the code, I'd love to play with it... -- Martijn van Oosterhout <kleptog@xxxxxxxxx> http://svana.org/kleptog/ > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a > tool for doing 5% of the work and then sitting around waiting for someone > else to do the other 95% so you can sue them.
Attachment:
pgp6zkQ0BC4Tr.pgp
Description: PGP signature