Complex Numbers & binary fractions
Beat Cornaz
beat.c at hetnet.nl
Fri Sep 16 06:47:37 EDT 2005
Cubist wrote :
>function DecFrac2BinFrac TheFrac, ThePrecision
> # TheFrac is *assumed* to have nothing to the *left* of the decimal point
> # ThePrecision is *assumed* to be a positive integer
> # you can write the code to handle those cases yourself, if need be, right?
>
> if ThePrecision = "" or ThePrecision < 1 then put 10 into ThePrecision
> # so the user can just supply a fraction and not care
>
> set the numberFormat to "0.#####"
> #you want to make sure there's a leading 0 before the decimal
> put "." into Rezult
> repeat # yes, it's an infinite loop. the escape test will be inside it
> multiply TheFrac by 2
> put char 1 of TheFrac after Rezult
> # because of numberFormat, char 1 here should be either 0 or 1
> if the length of TheFrac > ThePrecision or TheFrac = 0 then exit repeat
> delete char 1 of TheFrac
> end repeat
> return Rezult
> end DecFrac2BinFrac
Thanks Cubist. I'm often surprised at the original ways of coding
that show up in this group. I'm refering here to > # because of
numberFormat, char 1 here should be either 0 or 1.
I want to point your attention to a little mistake:
> if the length of TheFrac > ThePrecision or TheFrac = 0 then exit repeat
I think it should read :
if the length of Rezult > ThePrecision or TheFrac = 0 then exit repeat
I'm a bit surprised that no one has done anything with complex
numbers. So I'll have to whip up something myself. If someone is
interested, I'm willing to share the code (once I've coded it). mail
me off list if you want to get it.
Greetings, Beat
--
More information about the use-livecode
mailing list