Small valued numbers or scientific computing

Mike Bonner bonnmike at gmail.com
Sun Jun 23 23:34:19 EDT 2013


Not sure it will work as you need it too, but one last test before I crash.

I put a calc into a field and did this:

   *put* format("%1.60e",value(field 1))

Bipassing do, and it seems to function well enough. Would have to wrap it
in a try/catch or something since you can't count on the user putting in
things perfectly, but it might be a way.


On Sun, Jun 23, 2013 at 9:15 PM, John <john at onechip.com> wrote:

> Mike,
>
>    I need to dig a bit deeper and perhaps make a test app.  The issue
> could be a bit more complicated in my case as the math is happening behind
> a "do" statement.
>
>    There is field in which the user enters what they want to calculate.  I
> take that and add a "put" and an "into" targeting a destination field where
> the answer goes.  The now, correctly formatted liveCode, is executed with a
> "do" statement.  It appears that using a "do" changes things.
>
>     The same thing seems to happen in the message box.  If I enter "put
> (1234567890123e-10 * 1e-170)" into the message box, I get a result of 0
> while "put (1234567890123 * 1)" gives the expected 1234567890123.
>
>     I need the ability to handle function calls (like cos) and save values
> to variables from the users entry. Perhaps I can manage to cleverly use the
> format statement in all of this but it might just be simpler to have the
> really odd, really long, numberFormat statement since it works.
>
>    Thanks for the input, I appreciate the help.
>
> John
>
>
> On Jun 23, 2013, at 7:48 PM, Mike Bonner <bonnmike at gmail.com> wrote:
>
> > Hmm. was just messing with it in the message box.. I'm not a math guy,
> but
> > seems that when using format you shouldn't need to specify the
> numberformat.
> >
> > I did this..  put format("%1.60e",1.23456e-41 * 1e-20)  where 60 is the
> > desired precision.  Seems to work, same type of result but you specify
> the
> > precision in the format string rather than having to type 60 # (or
> however
> > many you need)...
> >
> > Just changed it based on your most recent mail that popped in.  Used: put
> > format("%1.60e",1234567890123e-10 * 1e-170)
> > message box shows  (precision 60)
> > 1.234567890123000166120503829534102198735876903021159008931759e-168
> >
> > (of course just popping it into the message box but still)
> >
> >
> >
> > On Sun, Jun 23, 2013 at 8:42 PM, John <john at onechip.com> wrote:
> >
> >> Mike,
> >>
> >>   Thanks for the tip.  I am using "format" for display purposes so that
> I
> >> get correctly formatted numbers but, unless I use "numberFormat" first,
> >> there is not enough precision available from the result of the
> >> multiplication and the result is 0.
> >>
> >>   It appears that "numberFormat" sets the number of decimal places LC
> >> uses to do the math and "Format" formats the results for display.
> >>
> >>   Any other thoughts?
> >>
> >> Thanks,
> >> John
> >>
> >>
> >>
> >>
> >> On Jun 23, 2013, at 7:31 PM, Mike Bonner <bonnmike at gmail.com> wrote:
> >>
> >>> look at the format function, specifically the "%#.##E" (or e)
> >> incantation.
> >>>
> >>>
> >>> On Sun, Jun 23, 2013 at 8:20 PM, John <john at onechip.com> wrote:
> >>>
> >>>>  It seems odd that I haven't stumbled into this before and I am sure I
> >>>> am doing something wrong, I just can't seem to find a better way
> around
> >> the
> >>>> issue of working with small numbers.
> >>>>
> >>>>  Suppose I want to multiply two small numbers such as: 1.23456e-41 *
> >>>> 1e-20.  Unless I am happy with a result of 0, I have to use a really
> odd
> >>>> numberFormat statement such as:
> >>>>
> >>>> set the numberformat to "0.##########...############" where " …"
> >>>> represents sixty or so '#'
> >>>>
> >>>> This seems really odd.  Surely there is a better way to do this.  Can
> >>>> someone help?
> >>>>
> >>>> Thanks,
> >>>> John
> >>>>
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> use-livecode mailing list
> >>>> use-livecode at lists.runrev.com
> >>>> Please visit this url to subscribe, unsubscribe and manage your
> >>>> subscription preferences:
> >>>> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>>>
> >>> _______________________________________________
> >>> use-livecode mailing list
> >>> use-livecode at lists.runrev.com
> >>> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >>> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>
> >>
> >> _______________________________________________
> >> use-livecode mailing list
> >> use-livecode at lists.runrev.com
> >> Please visit this url to subscribe, unsubscribe and manage your
> >> subscription preferences:
> >> http://lists.runrev.com/mailman/listinfo/use-livecode
> >>
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list