473,407 Members | 2,306 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,407 software developers and data experts.

Float based math class. Is it exist?

float sum = (float)Math.Sqrt( floatA*floatA + floatB*floatB);

I'm using DirectX with c#. But the Math class in .net framework has a
problem. It is "double" base!

So I'm doing type casting every line with Math class.

Is there any Math library float based?

Nov 17 '05 #1
17 11305
ki******@hanmail.net wrote:
float sum = (float)Math.Sqrt( floatA*floatA + floatB*floatB);

I'm using DirectX with c#. But the Math class in .net framework has a
problem. It is "double" base!

So I'm doing type casting every line with Math class.

Is there any Math library float based?


I don't think there's something like an alternate Math class that uses
float instead of double, no.

I assume there may be use cases where one really, explicitely doesn't
want the added precision of the double type over the float type. But in
most situations, I'd say why don't you just make your calculations with
double types, using the additional precision to your advantage, and then
cast the values just once when you pass them into the interface that
needs a float type? Is that not a usable approach for some reason I'm
not seeing?

Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
Nov 17 '05 #2
Hi!
needs a float type? Is that not a usable approach for some reason I'm
not seeing?


Float precision math is approx 2x faster than double.
Regards!
Atmapuri
Nov 17 '05 #3
Atmapuri <ja************@usa.net> wrote:
needs a float type? Is that not a usable approach for some reason I'm
not seeing?


Float precision math is approx 2x faster than double.


Possibly on your computer - certainly not on all computers, and
probably not even on all operations on your computer. I've seen
examples where using float was actually slower than double, because the
processor was doing a double calculation internally, and making it
float just incurred the overhead of conversion both ways.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Hi!
needs a float type? Is that not a usable approach for some reason I'm
not seeing?


Float precision math is approx 2x faster than double.
Regards!
Atmapuri
Nov 17 '05 #5
Atmapuri <ja************@usa.net> wrote:
needs a float type? Is that not a usable approach for some reason I'm
not seeing?


Float precision math is approx 2x faster than double.


Possibly on your computer - certainly not on all computers, and
probably not even on all operations on your computer. I've seen
examples where using float was actually slower than double, because the
processor was doing a double calculation internally, and making it
float just incurred the overhead of conversion both ways.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
1.
because the processor was doing a double calculation internally
Mr.Jon Skeet , Do you mean 64bit processor?
I can't image a situation that double is calculated faters than float.
Even in 64bit processor. Especially dealling directx functions. ( All
directx functions are float based)

2. There are two reasons why I want float based math
First, float precision math is 2x faster than double. It is said by
Atmapuri.
Second, type casting is severe work if it deals thousands of points.
All of the point in vertexbuffer should be calculated by math class.
and should be saved to float data every render frame.

Nov 17 '05 #7
1.
because the processor was doing a double calculation internally
Mr.Jon Skeet , Do you mean 64bit processor?
I can't image a situation that double is calculated faters than float.
Even in 64bit processor. Especially dealling directx functions. ( All
directx functions are float based)

2. There are two reasons why I want float based math
First, float precision math is 2x faster than double. It is said by
Atmapuri.
Second, type casting is severe work if it deals thousands of points.
All of the point in vertexbuffer should be calculated by math class.
and should be saved to float data every render frame.

Nov 17 '05 #8
<ki******@hanmail.net> wrote:
1.
> because the processor was doing a double calculation internally

Mr.Jon Skeet , Do you mean 64bit processor?
No.
I can't image a situation that double is calculated faters than float.
Even in 64bit processor. Especially dealling directx functions. ( All
directx functions are float based)
In some 32-bit processors, I believe there is no microcode support for
performing some floating point operations in less than 80 bits. In
other words, everything's already being converted.
2. There are two reasons why I want float based math
First, float precision math is 2x faster than double. It is said by
Atmapuri.
I'm afraid I don't know who Atmapuri is, but things may have changed
since he said that anyway.
Second, type casting is severe work if it deals thousands of points.
All of the point in vertexbuffer should be calculated by math class.
and should be saved to float data every render frame.


Certainly if you need to do a lot of converting, that could be a
performance problem - but as I said, it's possible that the processor
is having to do that conversion anyway for each floating point op.

You seem utterly convinced that you need to do everything with 32-bit
operations though, so I'll just leave it at "No, I don't know of any
maths libraries that provide the functionality you want."

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #9
<ki******@hanmail.net> wrote:
1.
> because the processor was doing a double calculation internally

Mr.Jon Skeet , Do you mean 64bit processor?
No.
I can't image a situation that double is calculated faters than float.
Even in 64bit processor. Especially dealling directx functions. ( All
directx functions are float based)
In some 32-bit processors, I believe there is no microcode support for
performing some floating point operations in less than 80 bits. In
other words, everything's already being converted.
2. There are two reasons why I want float based math
First, float precision math is 2x faster than double. It is said by
Atmapuri.
I'm afraid I don't know who Atmapuri is, but things may have changed
since he said that anyway.
Second, type casting is severe work if it deals thousands of points.
All of the point in vertexbuffer should be calculated by math class.
and should be saved to float data every render frame.


Certainly if you need to do a lot of converting, that could be a
performance problem - but as I said, it's possible that the processor
is having to do that conversion anyway for each floating point op.

You seem utterly convinced that you need to do everything with 32-bit
operations though, so I'll just leave it at "No, I don't know of any
maths libraries that provide the functionality you want."

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #10
Thanks for your kindness and patience. ^_^

Nov 17 '05 #11
Thanks for your kindness and patience. ^_^

Nov 17 '05 #12
On Mon, 22 Aug 2005 17:12:23 +0200, "Atmapuri"
<ja************@usa.net> wrote:
Float precision math is approx 2x faster than double.


Not on the Intel x86 architecture...
--
http://www.kynosarges.de
Nov 17 '05 #13
On Mon, 22 Aug 2005 17:12:23 +0200, "Atmapuri"
<ja************@usa.net> wrote:
Float precision math is approx 2x faster than double.


Not on the Intel x86 architecture...
--
http://www.kynosarges.de
Nov 17 '05 #14
On Tue, 23 Aug 2005 06:22:46 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
In some 32-bit processors, I believe there is no microcode support for
performing some floating point operations in less than 80 bits. In
other words, everything's already being converted.


The FPU of the x86 line always performs calculations at 80 bit
precision, that's why you don't get any speedup for using float
instead of double (other than some memory transfer savings).

NB: In an earlier discussion I was notified that you can explicitly
put the FPU into 32-bit IEEE mode, but (a) I don't think it's actually
faster -- Intel just provides this feature to accomodate existing
programs; and (b) the .NET libraries don't use this mode anyway.

<ki******@hanmail.net> wrote:
2. There are two reasons why I want float based math
First, float precision math is 2x faster than double. It is said by
Atmapuri.


Tip: Don't believe everything you read on the Internet...

By the way, I think professional game developers use the FPU's SIMD
unit (MMX/SSE/3DNow) extensively for their math. These units do
support single-precision math natively, and you may in fact get a
factor 2 speedup if you use them (since they split their 64-bit
registers into two 32-bit registers for that job). However, .NET does
not support these units at all, so that won't help you either.
--
http://www.kynosarges.de
Nov 17 '05 #15
On Tue, 23 Aug 2005 06:22:46 +0100, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
In some 32-bit processors, I believe there is no microcode support for
performing some floating point operations in less than 80 bits. In
other words, everything's already being converted.


The FPU of the x86 line always performs calculations at 80 bit
precision, that's why you don't get any speedup for using float
instead of double (other than some memory transfer savings).

NB: In an earlier discussion I was notified that you can explicitly
put the FPU into 32-bit IEEE mode, but (a) I don't think it's actually
faster -- Intel just provides this feature to accomodate existing
programs; and (b) the .NET libraries don't use this mode anyway.

<ki******@hanmail.net> wrote:
2. There are two reasons why I want float based math
First, float precision math is 2x faster than double. It is said by
Atmapuri.


Tip: Don't believe everything you read on the Internet...

By the way, I think professional game developers use the FPU's SIMD
unit (MMX/SSE/3DNow) extensively for their math. These units do
support single-precision math natively, and you may in fact get a
factor 2 speedup if you use them (since they split their 64-bit
registers into two 32-bit registers for that job). However, .NET does
not support these units at all, so that won't help you either.
--
http://www.kynosarges.de
Nov 17 '05 #16
You are perfect man!

I don't think there can be better answer than yours.

Sincerely.

Nov 17 '05 #17
You are perfect man!

I don't think there can be better answer than yours.

Sincerely.

Nov 17 '05 #18

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

Similar topics

5
by: john smith | last post by:
Hi, I am trying to initialize a float in a class. For example: class ABC{ public:
5
by: Jon Cosby | last post by:
I don't have the Math class available in CS. I have it in VB. Does anyone know why this would be? Jon
4
by: Ryan Liu | last post by:
Is there a good reason that Decimal does not have Ceiling() method, only Math class has? Thanks!
10
by: Ing. Carlos Villaseñor M. | last post by:
Hi everybody! I have developed in C# and got in a news group a math class that make matrix operations, eigenvals, eigenvecs, stat functions and much more, but now I trying to develop software in...
6
by: Lee | last post by:
I'd like to implement a generic class that takes as its Type-parameter a numeric type (e.g. (U)Int16/32/64, float, double, decimal, etc.). The problem is that, having validated the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.