Re: [Factor-talk] unexpected integer from a float sum

2018-12-19 Thread John Benediktsson
I’m surprised also. They should display the way they do in other languages 
examples. That seems like a bug. 

> On Dec 18, 2018, at 12:25 PM, Alexander Ilin  wrote:
> 
> USE: math.functions:round instead
> 
> 18.12.2018, 15:14, "Georg Simon" :
>> Below I pasted a result from my listener I do not understand.
>> 
>> The result of sum looks like 137.99 which is right.
>> But the integer I made out of it is 13798 which is wrong.
>> 
>> A typed in 137.99 gives the result I expect.
>> 
>> What am I missing ?
>> --
>> Press F1 at any time for help.
>> Factor 0.99 x86.64 (1889, heads/master-f77d46f0c8, Dec 1 2018 21:02:41)
>> [GCC 7.3.0] on linux
>> 
>> IN: scratchpad { -13.8 -21.8 -3.99 -3.0 -15.7 126.98 -8.9 100.0 -21.8 }
>> sum
>> 
>> --- Data stack:
>> 137.99
>> IN: scratchpad 100 *
>> 
>> --- Data stack:
>> 13799.0
>> IN: scratchpad >integer .
>> 13798
>> IN: scratchpad 137.99 100 * >integer .
>> 13799
> 
> ---=--- 
> Александр
> 
> 
> 
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk


___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] unexpected integer from a float sum

2018-12-19 Thread Georg Simon
Thank you.

I have not considered that floating point numbers are displayed rounded.

Am Tue, 18 Dec 2018 16:40:21 -0800
schrieb John Benediktsson :

> Your number isn't quite 13799, represented as a floating point
> number, but maybe we could print it out with additional digits.  See,
> for example, the same result in other languages:
> 
> Here is Java:
> 
> $ cat foo.java
> class foo {
> 
> public static void main(String[] args) {
> double[] foo = { -13.8, -21.8, -3.99, -3.0, -15.7, 126.98, -8.9,
> 100.0, -21.8 };
> 
> double x = 0.0;
> for (int i = 0; i < foo.length; i++) {
> x += foo[i];
> }
> System.out.println(x);
> System.out.println(x*100);
> System.out.println((int)(x*100));
> }
> }
> $ javac foo.java
> $ java foo
> 137.989998
> 13798.9998
> 13798
> 
> 
> Or Python:
> 
> >>> a = [-13.8, -21.8, -3.99, -3.0, -15.7, 126.98, -8.9, 100.0, -21.8]
> >>> sum(a)  
> 137.989998
> >>> sum(a) * 100  
> 13798.9998
> >>> int(sum(a) * 100)  
> 13798
> 
> 
> 
> 
> On Tue, Dec 18, 2018 at 12:26 PM Alexander Ilin 
> wrote:
> 
> > USE: math.functions:round instead
> >
> > 18.12.2018, 15:14, "Georg Simon" :  
> > > Below I pasted a result from my listener I do not understand.
> > >
> > > The result of sum looks like 137.99 which is right.
> > > But the integer I made out of it is 13798 which is wrong.
> > >
> > > A typed in 137.99 gives the result I expect.
> > >
> > > What am I missing ?
> > > --
> > > Press F1 at any time for help.
> > > Factor 0.99 x86.64 (1889, heads/master-f77d46f0c8, Dec 1 2018
> > > 21:02:41) [GCC 7.3.0] on linux
> > >
> > > IN: scratchpad { -13.8 -21.8 -3.99 -3.0 -15.7 126.98 -8.9 100.0
> > > -21.8 } sum
> > >
> > > --- Data stack:
> > > 137.99
> > > IN: scratchpad 100 *
> > >
> > > --- Data stack:
> > > 13799.0
> > > IN: scratchpad >integer .
> > > 13798
> > > IN: scratchpad 137.99 100 * >integer .
> > > 13799  
> >
> > ---=---
> >  Александр
> >
> >
> >
> > ___
> > Factor-talk mailing list
> > Factor-talk@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/factor-talk
> >  



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] unexpected integer from a float sum

2018-12-18 Thread John Benediktsson
Your number isn't quite 13799, represented as a floating point number, but
maybe we could print it out with additional digits.  See, for example, the
same result in other languages:

Here is Java:

$ cat foo.java
class foo {

public static void main(String[] args) {
double[] foo = { -13.8, -21.8, -3.99, -3.0, -15.7, 126.98, -8.9, 100.0,
-21.8 };

double x = 0.0;
for (int i = 0; i < foo.length; i++) {
x += foo[i];
}
System.out.println(x);
System.out.println(x*100);
System.out.println((int)(x*100));
}
}
$ javac foo.java
$ java foo
137.989998
13798.9998
13798


Or Python:

>>> a = [-13.8, -21.8, -3.99, -3.0, -15.7, 126.98, -8.9, 100.0, -21.8]
>>> sum(a)
137.989998
>>> sum(a) * 100
13798.9998
>>> int(sum(a) * 100)
13798




On Tue, Dec 18, 2018 at 12:26 PM Alexander Ilin  wrote:

> USE: math.functions:round instead
>
> 18.12.2018, 15:14, "Georg Simon" :
> > Below I pasted a result from my listener I do not understand.
> >
> > The result of sum looks like 137.99 which is right.
> > But the integer I made out of it is 13798 which is wrong.
> >
> > A typed in 137.99 gives the result I expect.
> >
> > What am I missing ?
> > --
> > Press F1 at any time for help.
> > Factor 0.99 x86.64 (1889, heads/master-f77d46f0c8, Dec 1 2018 21:02:41)
> > [GCC 7.3.0] on linux
> >
> > IN: scratchpad { -13.8 -21.8 -3.99 -3.0 -15.7 126.98 -8.9 100.0 -21.8 }
> > sum
> >
> > --- Data stack:
> > 137.99
> > IN: scratchpad 100 *
> >
> > --- Data stack:
> > 13799.0
> > IN: scratchpad >integer .
> > 13798
> > IN: scratchpad 137.99 100 * >integer .
> > 13799
>
> ---=---
>  Александр
>
>
>
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] unexpected integer from a float sum

2018-12-18 Thread Alexander Ilin
USE: math.functions:round instead

18.12.2018, 15:14, "Georg Simon" :
> Below I pasted a result from my listener I do not understand.
>
> The result of sum looks like 137.99 which is right.
> But the integer I made out of it is 13798 which is wrong.
>
> A typed in 137.99 gives the result I expect.
>
> What am I missing ?
> --
> Press F1 at any time for help.
> Factor 0.99 x86.64 (1889, heads/master-f77d46f0c8, Dec 1 2018 21:02:41)
> [GCC 7.3.0] on linux
>
> IN: scratchpad { -13.8 -21.8 -3.99 -3.0 -15.7 126.98 -8.9 100.0 -21.8 }
> sum
>
> --- Data stack:
> 137.99
> IN: scratchpad 100 *
>
> --- Data stack:
> 13799.0
> IN: scratchpad >integer .
> 13798
> IN: scratchpad 137.99 100 * >integer .
> 13799

---=--- 
 Александр



___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk