How often do you find yourself using floating point data typ

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
tkahn6
Posts: 11
Joined: Sat Jul 11, 2009 5:14 pm

How often do you find yourself using floating point data typ

Post by tkahn6 »

I haven't had to use a float or double yet. Does this come up in kernel space development?

Thanks!
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: How often do you find yourself using floating point data typ

Post by Firestryke31 »

I've used it for color depth conversion (i.e. 24bit -> 16bit) but that was a while ago. It was more for my bootloader, though, and I don't really use it anymore. At the moment I can't think of anything kernel-specific (i.e. not something more suited to a driver or user-space library) that requires a float, though.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: How often do you find yourself using floating point data typ

Post by earlz »

I just about never use floats unless it's part of some programming course in school... (Java's best friend is floats apparently)

The only real time I've used floats in any program I made as a hobby was for a little tool to calculate from my clock out stubs how much my check should be.. I would have been perfectly happy hacking around a fixed point though..
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: How often do you find yourself using floating point data typ

Post by 01000101 »

I have float/double/long double and SSE support built-in to my kernel (if supported). I primarily use doubles and long doubles.

I use them quite often though, I perform a lot of averaging and want to make sure I maintain precision. I also have coded in double/long double printing support into my printf. There's not a lot that needs to be set up to support FPU ops, see the FPU wiki article and just make sure you use FSAVE and such when you use it in a multi-tasking environment.
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: How often do you find yourself using floating point data typ

Post by cyr1x »

The only time I used floats(libgmp) was in a high-precision PI-calculation-programm.
I never used the standard floats (like in C).
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Re: How often do you find yourself using floating point data typ

Post by mathematician »

tkahn6 wrote:I haven't had to use a float or double yet. Does this come up in kernel space development?

Thanks!
Personally I seldom use a float no matter what the type of development. Unless you are writing a program which makes explicit use of mathematics (or at least arithmetic), I wouldn't worry about it too much.
The continuous image of a connected set is connected.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: How often do you find yourself using floating point data typ

Post by Brendan »

Hi,
tkahn6 wrote:I haven't had to use a float or double yet. Does this come up in kernel space development?
I've never used floating point in any kernel, partly because my kernels are designed to work on CPUs that don't have FPU, and partly because I don't save FPU/MMX/SSE state during task switches unless it's necessary (where using FPU in the kernel makes this necessary, and therefore increases the cost of task switches). I can't think of anything that I would have wanted to use FPU for either - the closest would have been calculating timer counts (e.g. "PIT_count = (3579545 / 3) / desired_frequency") but this has to be an integer anyway, so there's no reason to use float/double for extra accuracy.

I never really used signed integers either. Almost everything uses unsigned integers, because almost everything is table indexes or addresses or bitfields.

FPU would have made one part of my boot code easier (GTF calculations for video modes), and I've been using floats/doubles a lot lately for bitmap image processing, but a micro-kernel doesn't do anything like that.

@01000101: Not sure why you'd need floats/doubles for averaging (or what you use averaging for). If the data is integers (which IMHO is likely), then you can keep track of the sum and the count with integers without any precision loss, and find the average with one division (where an integer answer can be accurate to within 0.5 without using fixed point).

Note: When I want "round to nearest" integer division, I do something like:

Code: Select all

    mov eax, <dividend_low_32bits>
    mov edx, <dividend_high_32bits>
    mov ecx, <divisor>
    div ecx           ;eax = quotient, edx = remainder
    dec ecx           ;ecx = divisor - 1
    add edx,edx       ;edx = remainder * 2
    cmp ecx,edx       ;Set carry flag if (remainder * 2) > (divisor - 1)
    adc eax,0

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
i586coder
Member
Member
Posts: 143
Joined: Sat Sep 20, 2008 6:43 am

Re: How often do you find yourself using floating point data typ

Post by i586coder »

Brendan wrote:Hi,
tkahn6 wrote:I haven't had to use a float or double yet. Does this come up in kernel space development?
I've never used floating point in any kernel, partly because my kernels are designed to work on CPUs that don't have FPU,
Me too. and i think FPU operations not needed in kernel :lol: ,if so please tell me where :roll:

CheerS,
a.T.d
Distance doesn't make you any smaller,
but it does make you part of a larger picture.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How often do you find yourself using floating point data typ

Post by Solar »

Brendan wrote:...I don't save FPU/MMX/SSE state during task switches unless it's necessary (where using FPU in the kernel makes this necessary, and therefore increases the cost of task switches).
Important point, here. Saving / restoring FPU state is a costly operation, which can easily be avoided because you don't exactly need floats for kernel-space code AFAICT.
Every good solution is obvious once you've found it.
Post Reply