473,803 Members | 4,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Float based math class. Is it exist?

float sum = (float)Math.Sqr t( 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 11349
ki******@hanmai l.net wrote:
float sum = (float)Math.Sqr t( 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.co m>
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.co m>
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******@hanma il.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #9
<ki******@hanma il.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #10

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

Similar topics

5
7259
by: john smith | last post by:
Hi, I am trying to initialize a float in a class. For example: class ABC{ public:
5
2067
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
3657
by: Ryan Liu | last post by:
Is there a good reason that Decimal does not have Ceiling() method, only Math class has? Thanks!
10
8828
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 Visual Basic.NET and wondering if does exist something like that for Basic.NET. I appreciate some help Thank you
6
1858
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 Type-parameter, I cannot do any arithmetic operations (+, -, *, /) on variables of that type. I tried creating wrapper-classes for the numeric types I will support and tried to derive them from a custom interface that specified the above 4 operators -- but...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5496
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.