Re: String to Float, without introducing errors

2022-12-19 Thread Ángel GR
On 2022-12-19 16:14, MRAB wrote: To be fair, I don't think I've never seen that notation either! I've only ever seen the form 6.67430E-11 ± 0.00015E-11, which is much clearer. We use it regularly in our experimental data: 6.3(4), 15.002(10). Things would become complex using exponential forms

Re: String to Float, without introducing errors

2022-12-19 Thread Michael F. Stemper
On 19/12/2022 09.14, MRAB wrote: On 2022-12-19 14:10, Peter J. Holzer wrote: On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: > G = Decimal( 6.6743015E-11 ) > r = Decimal( 6.371E6 ) > M = Decimal( 5.9722E24 ) What's the point of using Decimal

Re: String to Float, without introducing errors

2022-12-19 Thread Sabrina Almodóvar
On 17/12/2022 18:55, Stefan Ram wrote: > Grant Edwards writes: >> Yes, fixed point (or decimal) is a better fit for what he's doing. but >> I suspect that floating point would be a better fit for the problem >> he's trying to solve. > > I'd like to predict that within the next ten posts in this

Re: String to Float, without introducing errors

2022-12-19 Thread Greg Ewing
On 19/12/22 9:24 am, Stefan Ram wrote: So what's the time until a mass of one gram arrives at the ground versus a mass of ten grams? I think one needs "Decimal" to calculate this! Or you can be smarter about how you calculate it. Differentiating t with respect to m gives dt/dm = -0.5 * sqr

Re: String to Float, without introducing errors

2022-12-19 Thread Peter J. Holzer
On 2022-12-19 15:14:14 +, MRAB wrote: > On 2022-12-19 14:10, Peter J. Holzer wrote: > > He also interpreted the notation "6.67430(15)E-11" wrong. The > > digits in parentheses represent the uncertainty in the same number of > > last digits. So "6.67430(15)E-11" means "something between 6.67430E

Re: String to Float, without introducing errors

2022-12-19 Thread MRAB
On 2022-12-19 14:10, Peter J. Holzer wrote: On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: > G = Decimal( 6.6743015E-11 ) > r = Decimal( 6.371E6 ) > M = Decimal( 5.9722E24 ) What's the point of using Decimal if you start with nothing more th

Re: String to Float, without introducing errors

2022-12-19 Thread Thomas Passin
On 12/19/2022 9:10 AM, Peter J. Holzer wrote: On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: G = Decimal( 6.6743015E-11 ) r = Decimal( 6.371E6 ) M = Decimal( 5.9722E24 ) What's the point of using Decimal if you start with nothing more than

Re: String to Float, without introducing errors

2022-12-19 Thread Peter J. Holzer
On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: > On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: > > G = Decimal( 6.6743015E-11 ) > > r = Decimal( 6.371E6 ) > > M = Decimal( 5.9722E24 ) > > What's the point of using Decimal if you start with nothing more than > float accuracy? Right. He als

Re: String to Float, without introducing errors

2022-12-18 Thread Cameron Simpson
On 19Dec2022 08:53, Cameron Simpson wrote: I'm no expert on floating point coding for precision, but I believe that trying to work with values "close together" in magnitude is important because values of different scales inherently convert one of them to the other scale (i.e. similar sized exp

Re: String to Float, without introducing errors

2022-12-18 Thread Greg Ewing
On 19/12/22 6:35 am, Paul St George wrote: So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We want to illustrate the paper with animations. Because there is a problem, I am investigating in all areas. ... I would like to be in control of or fully aw

Re: String to Float, without introducing errors

2022-12-18 Thread Chris Angelico
On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: > G = Decimal( 6.6743015E-11 ) > r = Decimal( 6.371E6 ) > M = Decimal( 5.9722E24 ) What's the point of using Decimal if you start with nothing more than float accuracy? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: String to Float, without introducing errors

2022-12-18 Thread Cameron Simpson
On 18Dec2022 18:35, Paul St George wrote: So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me).

Re: String to Float, without introducing errors

2022-12-18 Thread dn
On 18/12/2022 10.55, Stefan Ram wrote: Grant Edwards writes: Yes, fixed point (or decimal) is a better fit for what he's doing. but I suspect that floating point would be a better fit for the problem he's trying to solve. I'd like to predict that within the next ten posts in this thread

String to Float, without introducing errors

2022-12-18 Thread Paul St George
So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me). We want to illustrate the paper with animatio

Re: String to Float, without introducing errors

2022-12-18 Thread rbowman
On Sun, 18 Dec 2022 11:14:28 -0500, Dennis Lee Bieber wrote: > .. And maybe lament the days when a 3-digit result was acceptable in > math class -- being the typical capability in reading a standard (10" > scale) slide rule. Arguably more thought was given to what those three digits meant in the

Re: String to Float, without introducing errors

2022-12-18 Thread Thomas Passin
Thanks for filling us in! I wouldn't think the animations themselves would need such precision, though perhaps the calculations of the forces and motions do. One way to check might be to perturb the initial conditions a bit and see if the changes in the motions seem to be correspondingly smal

String to Float, without introducing errors

2022-12-18 Thread Paul St George
So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me). We want to illustrate the paper with animatio

RE: String to Float, without introducing errors

2022-12-17 Thread avi.e.gross
: python-list@python.org Subject: Re: String to Float, without introducing errors On 12/17/22 07:15, Thomas Passin wrote: > You have strings, and you want to end up with numbers. The numbers > are not integers. Other responders have gone directly to whether you > should use float or decim

Re: String to Float, without introducing errors

2022-12-17 Thread Chris Angelico
On Sun, 18 Dec 2022 at 09:46, Stefan Ram wrote: > > Grant Edwards writes: > >Yes, fixed point (or decimal) is a better fit for what he's doing. but > >I suspect that floating point would be a better fit for the problem > >he's trying to solve. > > I'd like to predict that within the next ten po

Re: String to Float, without introducing errors

2022-12-17 Thread dn
On 18/12/2022 01.39, Peter J. Holzer wrote: On 2022-12-17 12:51:17 +0100, Paul St George wrote: I have a large/long array of numbers in an external file. The numbers look like this: -64550.727 -64511.489 -64393.637 [...] When I bring the numbers into my code, they are Strings. To use the num

Re: String to Float, without introducing errors

2022-12-17 Thread Thomas Passin
On 12/17/2022 3:45 PM, Paul St George wrote: Thanks to all! It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then

Re: String to Float, without introducing errors

2022-12-17 Thread Peter J. Holzer
On 2022-12-17 21:45:06 +0100, Paul St George wrote: > It was the rounding rounding error that I needed to avoid (as Peter J. > Holzer suggested). The use of decimal solved it and just in time. I > was about to truncate the number, get each of the characters from the > string mantissa, and then do s

Re: String to Float, without introducing errors

2022-12-17 Thread Chris Angelico
On Sun, 18 Dec 2022 at 08:22, Grant Edwards wrote: > > On 2022-12-17, Chris Angelico wrote: > > >> It was the rounding rounding error that I needed to avoid (as Peter > >> J. Holzer suggested). The use of decimal solved it and just in > >> time. I was about to truncate the number, get each of the

Re: String to Float, without introducing errors

2022-12-17 Thread Grant Edwards
On 2022-12-17, Chris Angelico wrote: >> It was the rounding rounding error that I needed to avoid (as Peter >> J. Holzer suggested). The use of decimal solved it and just in >> time. I was about to truncate the number, get each of the >> characters from the string mantissa, and then do something

Re: String to Float, without introducing errors

2022-12-17 Thread Chris Angelico
On Sun, 18 Dec 2022 at 07:46, Paul St George wrote: > > Thanks to all! > It was the rounding rounding error that I needed to avoid (as Peter J. Holzer > suggested). The use of decimal solved it and just in time. I was about to > truncate the number, get each of the characters from the string man

Re: String to Float, without introducing errors

2022-12-17 Thread Paul St George
Thanks to all! It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: 64550.727 64550 + (7

Re: String to Float, without introducing errors

2022-12-17 Thread Thomas Passin
On 12/17/2022 1:41 PM, Mats Wichmann wrote: On 12/17/22 07:15, Thomas Passin wrote: You have strings, and you want to end up with numbers.  The numbers are not integers.  Other responders have gone directly to whether you should use float or decimal as the conversion, but that is a secondary m

Re: String to Float, without introducing errors

2022-12-17 Thread Mats Wichmann
On 12/17/22 07:15, Thomas Passin wrote: You have strings, and you want to end up with numbers.  The numbers are not integers.  Other responders have gone directly to whether you should use float or decimal as the conversion, but that is a secondary matter. If you have integers, convert with i

Re: String to Float, without introducing errors

2022-12-17 Thread Thomas Passin
You have strings, and you want to end up with numbers. The numbers are not integers. Other responders have gone directly to whether you should use float or decimal as the conversion, but that is a secondary matter. If you have integers, convert with integer = int(number_string) If you don't

Re: String to Float, without introducing errors

2022-12-17 Thread Peter J. Holzer
On 2022-12-17 12:51:17 +0100, Paul St George wrote: > I have a large/long array of numbers in an external file. The numbers > look like this: > > -64550.727 > -64511.489 > -64393.637 [...] > > When I bring the numbers into my code, they are Strings. To use the > numbers in my code, I want to chan

Re: String to Float, without introducing errors

2022-12-17 Thread Alan Gauld
On 17/12/2022 11:51, Paul St George wrote: > I have a large/long array of numbers in an external file. The numbers look > like this: > > -64550.727 > -64511.489 > -64393.637 > -64196.763 > -63920.2 > When I bring the numbers into my code, they are Strings. To use the > numbers in my code, I wan

Re: String to Float, without introducing errors

2022-12-17 Thread Weatherby,Gerard
https://docs.python.org/3/library/decimal.html Get Outlook for iOS<https://aka.ms/o0ukef> From: Python-list on behalf of Paul St George Sent: Saturday, December 17, 2022 6:51:17 AM To: python-list@python.org Subject: String to Float, without introducing

String to Float, without introducing errors

2022-12-17 Thread Paul St George
I have a large/long array of numbers in an external file. The numbers look like this: -64550.727 -64511.489 -64393.637 -64196.763 -63920.2 -63563.037 -63124.156 -62602.254 -61995.895 -61303.548 -60523.651 -59654.66 ... When I bring the numbers into my code, they are Strings. To use the numbers i