- mfrascinella@... wrote:
> I imagine it would be tricky to convert the result

That depends. you could just go and divide regardless and let it give

> to scientific notation.

you the result as E9 and E12 and whatever and visually choose the one

that looks nicest. I wouldn't really want to do a thing like that in

clip language, but the canonic way, if clips can hack it, is

3*INT(LOG(x)/3) for the exponent.

Axel

N.B: full quotes are evil - mfrascinella@... wrote:
> all these are evaluated by $Calc with the second one (1.43e9) being the

Agreed, although not all people might know that notation.

> simplest

> When I convert from wavelength to frequency, the result is in standard

If you mean just the exponent notation, that should be pretty straight

> notation, not scientific. 21 cm = 1427583133.333

> imagine it would be tricky to convert the result to scientific notation.

forward. For understanding SI-units you would probably want to get a

separate program and control it in your clip. I think the Unix program units

might be able to do the conversions. There are windows versions as well.

I can think of two ways of converting to scientific notation. THe first uses

a classic function called sprintf short for formatted print to String. It's

built-in in Perl and Python, is in the standard library in C (in which it

originated) and Java as well as being available to a huge number of other

langs. So does NoteTab have a sprintf function, by any chance?

Saying something like

$variable = sprintf("%.2g", 1427583133.333);

would do the job. %g says the next argument to the function should be

printed out in scientific notation and the number after the period gives the

precision. The above would place the string (text):

1.4e+009

in the variable $variable. The above syntax is Perl but basic sprintf

formatting works the same across languages.

There's a manual method. I'm no mathematician but here's my initial attempt

that seems to get most of the cases:

For simplicity suppose the input number is greater than 0 and might or might

not include a period I.e. a fractional part.

Here's a partly pseudo-code algorithm for arriving at the scientific

notation:

1. Compute the exponent like this:

$exponent = floor(log10($number));

The rationale here is as follows:

Log is the inverse function of exp so log10 tells you the exponent to which

a base 10 number needs to be raised to be equal to the input value. However,

the whole point of scientific notation is to use integer exponents. THus

round down any fractional part using floor.

2. Next evaluate:

$number = $number / 10 ** $exponent;

Where ** is the power of operator (^ in NoteTab). That is scientific

notation is usually writtten:

d.dddd where d stands for a digit. We need to get the number into a form

that's got only one digit before the fractional part. Dividing it by raising

10 to the power of the exponent seems to get you back to such a

presentation. In other words you are moving the period right or left by

dividing or multiplying by 10 repeatedly, from a conceptual stand point. As

I said I'm better with logic, as needed in programming, than pure math.

3. THe last step of processing you might need to do is to ensure that even

if the division in the previous step produced an integer (i.e. log10

returned an integer), we still add a period and a trailing 0. YOu do this by

scanning the string for a period and if It does not have one, you append the

string ".0" at the end of the input. Written in Perl that step would look

like:

$number .= '.0' if index($number, '.') == -1;

So if we had 1000 you would get 3 as the exponent and after division would

have 1. You would need to add ".0" to it to make it look consistent 1.0 that

is.

4. Now just print the string. It is the concatenation of the string variable

number, the exponent 'e',and the value of the variable named exponent.

I guess you could try converting the above algorithm to clip code. I'm

posting this at the dead of night Finnish local time and just quickly tested

the code in Perl. So human and or logical errors may still remain. And once

again I don't know any higher math period.

--

With kind regards Veli-Pekka Tätilä (vtatila@...)

Accessibility, game music, synthesizers and more:

http://www.student.oulu.fi/~vtatila - This was first sent last evening, but never appeared:

mfrascinella@... wrote:> I imagine it would be tricky to convert the result

That depends. you could just go and divide regardless and let it give

> to scientific notation.

you the result as E9 and E12 and whatever and visually choose the one

that looks nicest. I wouldn't really want to do a thing like that in

clip language, but the canonic way, if clips can hack it, is

3*INT(LOG(x)/3) for the exponent.

Axel

N.B: full quotes are evil - Hi,

I did some further study, especially of the note about math functions

that Sheri referred to (from 2003) and finally got the clip to

calculate the frequency in scientific notation. I took the logarithm

of the calculated frequency, used the FLOOR function to round the log

down to an integer, and divided the result by that power of 10 to get

scientific notation.

The prompts (now commented out) helped me verify each step of the

calculation.

Yours,

Michael F.

==========

H="Wavelength -> Frequency"

^!Set %wavelength%=^?[Enter the wavelength (cm)]

;^!Prompt ^%wavelength% cm

^!Set %frequency%=^$Calc(2.9979245800e10/^%wavelength%)$

;^!Prompt ^%wavelength% cm = ^%frequency% cycles/sec.

^!Set %log_frequency%=^$Calc(FLOOR(LOG10(^%frequency%)))$

;^!Prompt ^%log_frequency%

^!Prompt ^%wavelength% cm = ^$Calc(^%frequency%/1e^%log_frequency%;3)

$ x 10^^%log_frequency% cycles/sec (scientific notation)