Newbie quesion: Scientific notation



  • 1. $var = { }
    What does this means $var = { }
  • 2. FTP problem
    Hello, in the past I used Net::FTP for ftp and had no problems, however if I try to connect to a ftp url like I can't connect? $ftp = Net::FTP->new($url, Debug=>1 [, Passive=>1]) or die 'cannot conect'; Any ideas what the problem is?
  • 3. New errors of export image format
    "smallpond" < XXXX@XXXXX.COM > wrote in message news: XXXX@XXXXX.COM ... > It would be nice if when you post, you give some code and the actual > error that you are getting instead of your interpretation. Makes > it a lot easier to help you. The codes are as follows and now the problem becomes "Can't call method "png" on an undefined value at line 34." printing error message or not does not lead to great difference... The input file is like this: ========== 9 ~ 20.03 10 E 14.56 11 E 12.16 ========== #!/usr/bin/perl use GD::Graph; use GD::Graph::bars; $filename = $ARGV[0]; open(FP, $filename); while ($line = <FP>) { @words = split(/ /, $line); if ($words[1] =~ /[A-Z]/) { push @x, $words[0]; push @y, $words[2]; } } @data = (@x, @y); close FP; print $data[0], $data[1]; my $graph = GD::Graph::bars->new(400, 300) or die GD::Graph->error; $graph->set( title => 'B vs SS', ) or die $graph->error; #open(IMG, ">$filename.gif") or die $!; open(IMG, ">$filename.png") or die $!; binmode IMG; #$gd = $graph->plot(\@data)->gif; $graph->plot(\@data)->png or die $graph->error; print IMG $gd; close IMG;

Re: Newbie quesion: Scientific notation

Postby mdfoster44 » Thu, 03 Feb 2005 09:03:10 GMT

Ah, this helps alot thanks!  I just didn't find that before.
Well the number it uploads is not the float, in this case double, that
I want it to be.  I'll need to do a strtod.

Re: Newbie quesion: Scientific notation

Postby anno4000 » Thu, 03 Feb 2005 09:18:44 GMT

 < XXXX@XXXXX.COM > wrote in comp.lang.perl.misc:


Please be specific!  Telling us it is not what you want it to be helps

What is the data your code offers to the DB?  How does the DB receive it?
What does the DB give back, if anything?  That's the kind of info we 

No, you need it to be what the documentation of your database interface
wants it to be.  I have no idea what it expects, but I doubt it's described
as "a strtod":


Re: Newbie quesion: Scientific notation

Postby mdfoster44 » Fri, 04 Feb 2005 03:59:38 GMT

above it

The data point
The data (pt, x)

P1   4.50015068000000D-004
$number = 4.50015068000000D-004

This is now just a string, I've been incorrectly feeding this to the
where it is expecting a double( double(20,6)).
Which explains why the DB returns

I need to convert the string stored in $number to a double number.
string to double (strtod).  So from perldoc -q "is a number", I've

use POSIX qw(strtod);
my $double = strtod($number);

However, the strtod function doesn't like the "D" in my number, ie
4.50015068000000D-004 needs to be 4.50015068000000e-004.  So I do a
Thanks for your pointer, sorry for my being vague.


Similar Threads:

1.Newbie quesion: Scientific notation


I'm trying to upload some data into a MySQL database.

Could someone please advise me how I handle scientific notation?

What I have sofar:

The data (pt, x)

P1   4.50015068000000D-004

My regex expressions, I've been experimenting with:

regex1: P\d+\s+(-?([0-9]+(\.[0-9]*)?|\.[0-9]+))/)
does not catch the scientific notation

regex2: P\d+\s+([+-]?(\d+(\.\d*)?|\.\d+)([eEdD][+-]?\d+))/)
does catch the scientific notation.  I then say,
$number = $1;

# Insert data
$dbh->do("INSERT INTO data(x) VALUES (?)",undef, $number);

How do I upload the number to the database?  If I do it as above it is

Thanks your help.


2.Convert Scientific Notation to decimal equivalent

How can I detect this, I have been running some code for a few days to develop some files and ran into the situation where I am getting the following data for input:

14.95313 14.45312 0
14.95313 1.570813E-015 0
14.95313 -14.45313 0
-14.95313 -28.90625 0
-14.95313 -14.45313 0
-14.95313 1.570813E-015 0
-14.95313 14.45312 0
14.95313 -28.90625 0
0 -28.90625 0
-14.95313 28.90625 0
0 28.90625 0
14.95313 28.90625 0

And my code is skipping some lines as it checks for any erroneous data:
next if grep (/[^0-9.-]/, @data);
But that thinks the scientific notation is bad. I searched the net and didn't find anything. How can I match this specific pattern and convert it?


3.print flips to scientific notation when integer exceeds 15 decimal digits

Philip Potter wrote:

> I would guess that these numbers are being stored in floats, and that
> these floats are 64-bit double precision, with 53 bits of mantissa.
> That means that there are just under 16 decimal digits of precision in
> these numbers. print and friends seem to automatically print no more
> than 15 digits of precision:
> [...]
> You probably want to use bignums instead. If you are dealing with
> large integers, where precision down to the units place is important,
> you definitely want bignums and not floats.
> H:\>perl -e "use bignum; my $i = 999999999999997; print $i, ' ',$i+4,qq[\n];"
> 999999999999997 1000000000000001
> the bignum pragma makes $i into a Math::BigInt object rather than a
> floating-point value.
> Your solution (a non-obvious printf format) is a bad one because while
> it solves the problem of output, it doesn't solve the problem of
> representation. As soon as you try to store an integer bigger than
> 2^53 (approximately 9e15) you will lose significance:
> [...]
> In answer to your question, the behaviour of print is probably the
> correct behaviour, since there's no point printing more precision than
> you store. So it's a self bug.

Many thanks for the reply.

Following the initial surprise, my main concern was that attempts to 
unearth a description or explanation (i.e. documentation) for the 
observed behaviour was so tricky.  For instance, there was nothing 
obvious in the relevant parts of "Programming Perl".

So I'm happy to categorise it as "self bug", although I'd like to 
include an element of "documentation weakness" in there and I'd be happy 
to assist someone in trying to improve the latter.

Anyway, your explanation was useful and gives us sufficient to decide 
how to address our local use of these numbers.  (In our case, they are 
human-oriented accumulated byte-counts, for which we don't actually need 
that significance/precision.)


: David Lee
: ECMWF (Data Handling System)
: Shinfield Park
: Reading  RG2 9AX
: Berkshire
: tel:    +44-118-9499 362
: email:   XXXX@XXXXX.COM 

4.print flips to scientific notation when integer exceeds 15 decimal digits

Although I've used perl for many years, I've just been surprised (in the 
unpleasant sense) by a recent event.  Given a variable, say "$int", 
which is a growing integer, I would expect "print $int" to print it as a 
simple integer; indeed it usually does so.  But when its size takes it 
from 15 decimal digits to 16 decimal digits, that "print" flips the 
output into scientific notation:

Ouch.  The surprise is especially nasty when this output data is then 
used as input data for another program that expects an integer.

This is consistent across a variety of OSes (although all perl 5.8.8).

I eventually managed to track down a way to achieve the desired result 
with a non-obvious "printf" format.  (I leave that, and its clear 
user-oriented explanation, as an exercise for the reader!)

I'm not aware of any documentation about this surprise. Is this a 
program bug or a documentation bug?  (Or a self bug?)

Is there a more appropriate forum than "beginners@..." to raise this?

: David Lee
: ECMWF (Data Handling System)
: Shinfield Park
: Reading  RG2 9AX
: Berkshire
: tel:    +44-118-9499 362
: email:   XXXX@XXXXX.COM 

5.basic quesion reg file opening

why cant i specify like this to open a file

open AG, " < ../new/new_name*";

Here  i could open  the file only if i mention the full file name if i
give it as * i could not open the file it possible to open the
file with out mentioning the full file name coz in my progrm the file
name new_name is only constant after that i append date to it so varies

thanks for the help

6. Scientific Number problem again!

7. an Invitation to be Involved in a Survey on Developing Scientific Computing Software

8. Using the () list notation with $scalars

Return to PERL


Who is online

Users browsing this forum: No registered users and 64 guest