Jump to content

Recommended Posts

Posted
Hello!


I have Christmas present to you:


on-line Special Relativity Mass Calculator




It takes rest mass m0, velocity and speed of light as parameters, in units you want, and calculates final mass.


It's working with floating point precision of web browser - it's using JavaScript to calculate mass.


ps. It appears that the latest version of Chrome is buggy and there is need to click Calculate button. In Firefox it's immediately calculating after change of value.
Posted
The largest velocity that I am able to enter is


v = 299792457.99999997


after using 299792457.999999971 there is produced error/infinity (floating precision of computer, it might differ between web browsers, they have different implementations of JavaScript)


1 kg at rest mass has in such speed 54794158.00594377 kg (55 million times bigger)
Posted (edited)

Compilers don't have precision.

 

Precision is "property" of floating point format.

 

There are two built-in in math co-processors (which are part of processor since Intel 486)

 

IEEE 754

http://en.wikipedia.org/wiki/Single_precision_floating-point_format

32 bit floating point format

 

http://en.wikipedia.org/wiki/Double_precision_floating-point_format

64 bit floating point format

 

Using any low-level language such as C/C++ it's possible to code any precision custom floating point format.

But it's time and money consuming task, every math operation must be recreated and carefully tested.

 

JavaScript is interpreted language (script), so it's your web browser and your computer which is doing the all calculations.

It can't execute program which is on server, and running program from local disk would be serious leak in security (imagine somebody calling "dir c:" and he would have all structure of your disk... then do echo <c:\file.txt and have your data)

 

You can see mine calculator pressing ctrl-u to show page source html.

 

To have more precision there would be needed to:

- create c/c++ custom floating point format

- create c/c++ executable doing the same what does javascript code.

- change the way html form tag is handling entered data, and instead of using javascript send your data to web server, which would run PHP, and execute program, then send output to you.

Edited by Przemyslaw.Gruchala
Posted

80 bit floating point has precision just 18 digits in decimal (2^63 is the largest value it can have, without loosing precision).

 

I was rather thinking about making

 

class MineOwnFloat

{

const MineOwnFloat & operator += ( const MineOwnFloat &src );
const MineOwnFloat & operator -= ( const MineOwnFloat &src );
const MineOwnFloat & operator *= ( const MineOwnFloat &src );
const MineOwnFloat & operator /= ( const MineOwnFloat &src );
[etc. etc ]
};
And have f.e. 1000 digits precision. Or million digits precision.
Posted (edited)

Interesting article. But I bet author made serious mistake - in Visual Studio Project Properties window Code Generation used Floating Point Model - Precise.

In such model the all floating point operations are in math linked library and are called from main code (it's clearly visible while disassembling/watching generated assembly code).

After using Code Generation > Floating Point Model Fast, they're not called but inlined.

 

This explain why inline version:

 

	double sqrt13(double n)	{ 	  __asm{	     fld n	     fsqrt	   }	}

is 87% faster than regular sqrt( double n )

Edited by Przemyslaw.Gruchala

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.