#### Archived

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

# Tricky floating-point fudging

This topic is 5736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

There is an instruction to calculate the remainder (FPREM) of a number eg 1983.652%83.43=23 because 1983.652%83.43=23*83.43+64.762 Trouble is it''s even slower than division. Suppose I wanted to do it on nice numbers eg 17.74%16=1.74 ie find A%(2^B)=? By shifting -1 by B and then shifting it some more, simply ANDing this result with the stored floating-point number should give the answer a good ten or twenty times quicker. Basically, truncate the mantissa. I can work it out on paper but the big-endian and little-endian guff and floating-point representation is doing my head in. Can anyone simplify the problem, or point to someone who''s already done it? Thanks. ******** A Problem Worthy of Attack Proves It''s Worth by Fighting Back

##### Share on other sites
you can try multiplying the float by a large value, say 1,000,000 and cast it to a LARGE_INTEGER.

You can then use iteger divides, getting fast remainders, etc...

then when you are done, cast it to a double and divide by 1000000.

Sometimes I need to do crap like this to fix up some of my whacky code... its messy lol!

www.cppnow.com

##### Share on other sites
I don''t want to round, I want to "inverse-truncate"

********

A Problem Worthy of Attack
Proves It''s Worth by Fighting Back

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633765
• Total Posts
3013730
×