Asfianda / agk

Automatically exported from code.google.com/p/agk
0 stars 0 forks source link

Command to convert float to string in scientific notation for printing #166

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
According to the AGK documentation, floats are supposed to range from 3.4 E +/- 
38.

1) You can not hard wire 3.4E38 into your program. It ends up being 0 after 
compiling.
2) You can not write it out in terms of all the zeros either.
3) If you try to build the float up to the maximum or minimum values, these 
don't behave as expected either.

maxInt as integer
maxInt = 2147483647
minInt as integer
minInt = -2147483648

maxFloat as float
maxFloat = 340000000000000000000000000000000000000
minFloat as float
minFloat = -340000000000000000000000000000000000000

i as float
i = 2.0

j as float
j = 0.5

do
    print(minInt - 1)
    print(minInt)
    Print(maxInt)
    print(MaxInt + 1)
    print("")
    print(minFloat - 1)
    print(minFloat)
    print(maxFloat)
    print(maxFloat + 1)
    print(i)
    i = i * 2
    print(j)
    j = j/2
    Sync()
    sleep(1000)
loop

Original issue reported on code.google.com by richa...@muskingum.edu on 4 Dec 2011 at 12:24

GoogleCodeExporter commented 9 years ago
Sounds like either a help documentation change or compiler fix. I would 
appreciate a report on what values you expected to be reported for min and max 
integer and float? I know I've been a coder for over two decades, but I tend to 
stay away from the fussy edges of extremely large numbers ;)

Original comment by LeeBamberTGC@gmail.com on 5 Dec 2011 at 11:51

GoogleCodeExporter commented 9 years ago
Thanks Lee.  I don't have any expectations for the min and max values.  I too 
want to stay away from the fussy edges, so I need to know what they are for 
floats.  I'm using AGK to model physical systems.  Some quantities can be large 
and some can be small.  I'd like to be able to assign a variable using 
scientific notation.  I'd also like to be able to print a variable using 
scientific notation if its size exceeded some range.  In the example I 
provided, if you start with 1.0 and continually divide by 2, you eventually get 
0.0000.  I'm assuming the internal representation is working but the print 
command is truncating it.  If this is the predefined range, then it would be 
nice to switch to scientific notation at this point and display 5E-5.  On the 
flip side.. It appears that there is no predefined range for printing numbers 
greater than zero.  If there are 18 trailing zeroes, then 18 trailing zeros 
will be printed.  Again, it would be nice to switch to scientific notation.

By the way...
I'm really enjoying your product.  

Original comment by richa...@muskingum.edu on 6 Dec 2011 at 8:18

GoogleCodeExporter commented 9 years ago
Marked as feature request to add scientific notation on the display of float 
values.

Original comment by LeeBamberTGC@gmail.com on 6 Dec 2011 at 8:27

GoogleCodeExporter commented 9 years ago
May be will be useful to say that Microsoft uses the IEEE 754 floating-point 
standard, mainly used for x86. It requires that numbers have to be stored in 
binary format. Others stores the floats in ASCII. And if the format is not 
compatible with the platform it can give erroneous results sometimes without 
warnings.

If the standar used is C99, I'm not sure but I think its not supported by 
Microsoft from Visual C++ 2010

Original comment by javierto...@terra.es on 9 Dec 2011 at 4:13

GoogleCodeExporter commented 9 years ago
Two of you typed "fussy". Did you mean "fuzzy"?

I agree, Lee. Very large and very small numbers are scary :)

However, I would like it if the print command would only switch to scientific 
notation when the numbers get too large if the user wants it to. In other 
words, there should be a command to switch between displaying lots of zeroes 
and displaying scientific notation. I found it really annoying in DBPro when 
making space simulators that I could never tell exactly how far out a planet 
was because I didn't understand scientific notation.

David aka Clonkex

Original comment by clon...@yahoo.com.au on 14 Dec 2011 at 1:29

GoogleCodeExporter commented 9 years ago
If someone could dig out the sprintf format options for getting at the 
scientific notation modes, that would help hugely. I also agree the coder 
should have access to a print mode that uses scientific notation on any value.

Original comment by LeeBamberTGC@gmail.com on 14 Dec 2011 at 9:04

GoogleCodeExporter commented 9 years ago

Original comment by P.S.John...@gmail.com on 24 Aug 2014 at 1:11