473,320 Members | 1,831 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,320 software developers and data experts.

subnormal floating point numbers

Hi all,
first of all I beg your pardon if this question has been asked
before, but I was unable to find anything in the past posts.
I have written a piece of code that was supposed to be quite portable,
and uses a lot fp numbers. Everything goes well on PPC cpus, but on
some x86 CPU I get a dramatic loss of performance. After some
investigations I've discovered that the problem is caused by some
numbers becoming subnormal, PPC cpus seems to treat them quietly
without any significant loss of speed whereas on some x86 CPU I get
really very poor results as soon as these "strange" entities begin to
pop out...
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs? I don't need them and
for me it will be just ok to have a small quantity dropped to zero -
in fact, the code is written assuming implicitly that very small
number will eventually become zero.
I hope that there is a simple solution for the problem, apart from
reviewing any very single line of code and putting a lot of
if(issubnormal...) or whatever else...

Thanx in advance to everybody that can/will help me...

May 15 '07 #1
5 3673
On May 15, 3:27 pm, ultimatewarrior <ultimatecodewarr...@yahoo.it>
wrote:
first of all I beg your pardon if this question has been asked
before, but I was unable to find anything in the past posts.
I have written a piece of code that was supposed to be quite portable,
and uses a lot fp numbers. Everything goes well on PPC cpus, but on
some x86 CPU I get a dramatic loss of performance. After some
investigations I've discovered that the problem is caused by some
numbers becoming subnormal, PPC cpus seems to treat them quietly
without any significant loss of speed whereas on some x86 CPU I get
really very poor results as soon as these "strange" entities begin to
pop out...
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs? I don't need them and
for me it will be just ok to have a small quantity dropped to zero -
in fact, the code is written assuming implicitly that very small
number will eventually become zero.
I hope that there is a simple solution for the problem, apart from
reviewing any very single line of code and putting a lot of
if(issubnormal...) or whatever else...
I don't believe there is anything standard to effect this. I think
you're looking for a compiler switch (e.g., -fn on Sun C++). You
should ask in a group related to your compiler.

Cheers! --M

May 15 '07 #2
ultimatewarrior wrote:
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs?
Just assigning the subnormal to a double variable should force it to 0.

---
Walter Bright
Digital Mars C, C++, D programming language compilers
May 16 '07 #3
Walter Bright wrote:
ultimatewarrior wrote:
>Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs?

Just assigning the subnormal to a double variable should force it to 0.
If the subnormal doesn't propagate, this wouldn't solve the problem,
would it?

Regards,

Zeppe
May 16 '07 #4
On 16 Mag, 11:57, Zeppe <zeppe@.remove.all.this.long.comment.email.it>
wrote:
Walter Bright wrote:
ultimatewarrior wrote:
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs?
Just assigning the subnormal to a double variable should force it to 0.

If the subnormal doesn't propagate, this wouldn't solve the problem,
would it?
Well, I guess no. And I cannot change every bit of code in order to
replace any assignement from float to double.

I've probably found a workaround, anyway, using SSE instead of
standard FPU you can control (through the MXCSR register) how to deal
with subnormal numbers, you can instruct the CPU to treat them as
zeros (exactly what I need), unfortunately you need SSE because the
x87 FPU has no control over this (ok, SSE is there from PIII and
AthlonXP so I think I'll drop support for older CPUs...)

Has someone any experience with issues regarding the use of SSE for
floats (instead of the standard FPU)?

(BTW, thanx for your kind answers!)

May 16 '07 #5
"ultimatewarrior" <ul*****************@yahoo.itwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Hi all,
first of all I beg your pardon if this question has been asked
before, but I was unable to find anything in the past posts.
I have written a piece of code that was supposed to be quite portable,
and uses a lot fp numbers. Everything goes well on PPC cpus, but on
some x86 CPU I get a dramatic loss of performance. After some
investigations I've discovered that the problem is caused by some
numbers becoming subnormal, PPC cpus seems to treat them quietly
without any significant loss of speed whereas on some x86 CPU I get
really very poor results as soon as these "strange" entities begin to
pop out...
Does someone know if there is a way to disable subnormal floating
point numbers, maybe using standard c/c++ libs? I don't need them and
for me it will be just ok to have a small quantity dropped to zero -
in fact, the code is written assuming implicitly that very small
number will eventually become zero.
I hope that there is a simple solution for the problem, apart from
reviewing any very single line of code and putting a lot of
if(issubnormal...) or whatever else...

Thanx in advance to everybody that can/will help me...
Reading other responses, and your responses to their responses, perhaps you
should use double instead of float. My understanding is that double is
faster than float anyway on (most/all) platforms. It also seems this might
get rid of your subnormal problems. Especially since performance seems to
be an issue it seems like the right thing to do.
May 17 '07 #6

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

Similar topics

4
by: Roger Leigh | last post by:
Hello, I'm writing a fixed-precision floating point class, based on the ideas in the example fixed_pt class in the "Practical C++ Programming" book by Steve Oualline (O' Reilly). This uses a...
4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
31
by: JS | last post by:
We have the same floating point intensive C++ program that runs on Windows on Intel chip and on Sun Solaris on SPARC chips. The program reads the exactly the same input files on the two platforms....
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
10
by: Shawn | last post by:
Hello all, I apologize as I am sure this has probably been dealth with before... but I am doing an exercise from "Practical C Programming" and I have been unable to get it to work perfectly due to...
7
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
32
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon );...
23
by: ultimatewarrior | last post by:
Hi all, first of all I beg your pardon if this question has been asked before, but I was unable to find anything in the past posts. I have written a piece of code that was supposed to be quite...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.