Jump to content

Special Relativity Mass Calculator

Featured Replies

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.
  • Author
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)
  • Author

Anyone interested in reversed calculator? Input mass and velocity. Output rest mass.

 

Or enter mass and rest mass. Output velocity.

How about using more precision compiler? JavaScript call--->external compiled program with more precision compiler. Is it possible?

  • Author

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

  • Author

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.
  • Author

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

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.