473,569 Members | 2,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10549
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) 100000000000000 001590289110975 991804683608085 639452813897813 275577478387721 703810608134699 85856815104L 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
20536
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 { public static void main(String args) { double aValue = 123456789.1234; System.out.println(aValue); }
1
6774
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 been thinking a lot about this!!! any comments // modify floatfield using manipulators #include <iostream>
9
6515
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 binary numbers. To demonstrate my problem, try this code: ---- var binNumber = Math.pow(2,61);
28
10405
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: MyClass variable: iMyInteger
7
3780
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 access members by writing either of the two. obj.memberName
5
5066
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 notation no matter what the value is. (i.e. x = 123 would be displayed as x = 1.23e+02). The standard function "formatnumeric(x)" does not seem to be...
4
42725
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 should be able to print the result without containing the exponential notation. Please help me out.
8
5126
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 main(void) {
3
7255
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 8.0000000000000002E-2. This causes the xslt function format-number() to fail. I use it as <xsl:value-of select='format-number(8.0000000000000002E-2, "###,###.00")' />...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7665
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.