473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Exponential Notation and integers

Why are all numberical literals in exponential notation floats? To me
it is counter-intuitive for 1e3 to behave so fundamentally different
from 1000.

Timothy Fitz
Jul 18 '05 #1
4 10541
Timothy Fitz wrote:
Why are all numberical literals in exponential notation floats? To me
it is counter-intuitive for 1e3 to behave so fundamentally different
from 1000.


Probably primarily by convention. Most language use computerized
scientific notation to represent floating point numbers, not integers.
It makes sense, after all: should 1.344e3 be an int, but 1.344e2 be a
float?

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
I'll have to get over this sooner or later. Why not now?
-- Louis Wu
Jul 18 '05 #2
Erik Max Francis wrote:
Timothy Fitz wrote:
Why are all numberical literals in exponential notation floats? To me
it is counter-intuitive for 1e3 to behave so fundamentally different
from 1000.


Probably primarily by convention. Most language use computerized
scientific notation to represent floating point numbers, not integers.
It makes sense, after all: should 1.344e3 be an int, but 1.344e2 be a
float?


No, naturally 1.344e2 is the integer 134. <wink>
Maybe something like this would help the OP:
def number(x): .... return int(float(x))
.... MYCONSTANT = number('1.344e3')
print MYCONSTANT

1344

-Peter
Jul 18 '05 #3
My comment is more of a linguistic complaint. The differences between
an integer (type int or long) and a float in practice are large,
shouldn't 1e100 be of an integer type, since it -is- an integer? The
default practice here of making it a float just seems wrong.

[Peter Hansen]
Maybe something like this would help the OP:
def number(x): ... return int(float(x))
... MYCONSTANT = number('1.344e3')
print MYCONSTANT 1344


Yes, this would work in some cases, but not where it matters. Floats
have a significant amount of error when you are talking about very
large numbers, which is the only time you would want integer
exponential literals anyway, examples of errors:
long(1e100) 10000000000000000159028911097599180468360808563945 28138978132755774783877217038106081346998585681510 4L 1e20 == 10 ** 20 + 8192 True long(1e23) == 10 ** 23

False

The worst part is that because python will implicitly convert between
floats and integers, this can all happen silently and come back and
bite you where you least expect it.
Jul 18 '05 #4
Em Qui, 2004-11-18 às 15:49 -0800, Erik Max Francis escreveu:
Timothy Fitz wrote:
Why are all numberical literals in exponential notation floats? To me
it is counter-intuitive for 1e3 to behave so fundamentally different
from 1000.
Probably primarily by convention. Most language use computerized
scientific notation to represent floating point numbers, not integers.
It makes sense, after all: should 1.344e3 be an int, but 1.344e2 be a
float?

As far as readbility is concerned, some languages provide the 1_000_000
syntax (1000000 is just too hard to read). Is there any plans to add
this to python?

Thanks,
Fabio
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
I'll have to get over this sooner or later. Why not now?
-- Louis Wu

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ryoga | last post by:
How can I print out the value of a large double in plain decimal form without the exponential notation? For example (quick code): PlainPrint.java: --------------- public class PlainPrint {...
1
by: diegoandrade | last post by:
In this code the exponential part using scientific notation becomes e+002 is ther a way of changging the number of values after e so they can appear like e+02, only 2 values instead 3?? I have...
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
28
by: Phill | last post by:
Does anyone know the reasoning for Microsoft abandoning Hungarina Notation in C#? I have found it very usefull in C++. I like this style: constant: MY_CONSTANT methos: myMethod() class: ...
7
by: Sam Kong | last post by:
Hello! My question would not be very practical but just out of curiosity. In JavaScript, Array is a subclass of Object. Well maybe not exactly... but sort of... For normal objects, you can...
5
by: revansx | last post by:
Hi folks, I am programming a page that displays scientific data retrieved from a data source to an asp-web page and i would like to force all number to be formatted/displayed in scientific...
4
by: b4ukiran | last post by:
Hi all, I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I...
8
by: pereges | last post by:
Hi, can anyone please tell me what is wrong in this program and why does it keep givng nan as the output(eg. take input as 1.2e+10) ? #include <stdio.h> #define PLANCK 6.626068e10-34 int...
3
ashsa
by: ashsa | last post by:
Hi everyone, I am trying to display a numeric value fetched from an sql server table which is stored in the exponential notation. For eg, 0.08 is getting stored in the table as...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.