Is it possible to use float and double without setting FPU?
Is it possible to use float and double without setting FPU?
This is a very stupid question, but I thought I'd ask it nonetheless.
Now in my early initialization code I need to use double for calculations, but I'm not sure I can perform it as it seems to require the FPU to be preconfigured, is this true?
Now in my early initialization code I need to use double for calculations, but I'm not sure I can perform it as it seems to require the FPU to be preconfigured, is this true?
Re: Is it possible to use float and double without setting F
https://wiki.osdev.org/FPU
But why would you need to use floating-point calculations when booting an operating system?
But why would you need to use floating-point calculations when booting an operating system?
Re: Is it possible to use float and double without setting F
We can help convert your calculations to integer ones, if you'd like.
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Is it possible to use float and double without setting F
If you really need floating-point math, there are ways to do it without using the FPU.
But you probably don't need floating-point math.
But you probably don't need floating-point math.
Re: Is it possible to use float and double without setting F
To calculate when I should remap the hash map.iansjack wrote:But why would you need to use floating-point calculations when booting an operating system?
Code: Select all
m->remap = (uint32_t)(m->capacity * ((double)m->load_fac / 100));
Specifically this calculation I could replace with something like:
Code: Select all
m->remap = m->capacity / 4 * 3
Re: Is it possible to use float and double without setting F
The integer calculation
(if you want to round up) produces the same result. If you want to round down just use
Code: Select all
m->remap = (m->capacity * m->load_fac + 99) / 100
Code: Select all
m->remap = (m->capacity*m->load->fac) / 100
-
- Member
- Posts: 81
- Joined: Sun Apr 21, 2019 7:39 am
Re: Is it possible to use float and double without setting F
This would work better as a replacement for what I quoted above.mrjbom wrote: Specifically this calculation I could replace with something like:Code: Select all
m->remap = m->capacity / 4 * 3
Code: Select all
m->remap = m->capacity * 3 / 4
Re: Is it possible to use float and double without setting F
Why?iProgramInCpp wrote:This would work better as a replacement for what I quoted above.mrjbom wrote: Specifically this calculation I could replace with something like:Code: Select all
m->remap = m->capacity / 4 * 3
Code: Select all
m->remap = m->capacity * 3 / 4
Re: Is it possible to use float and double without setting F
You need to do the multiplication before the division (if using integer arithmetic) to get the correct result. And it’s best to use parentheses to ensure the correct order.whereasThe latter is obviously the result you want.
You’re looking for an integer result, so you don’t need floating-point calculations.
Code: Select all
8 * (75 / 100) = 0
Code: Select all
(8 * 75) / 100 = 6
You’re looking for an integer result, so you don’t need floating-point calculations.
Re: Is it possible to use float and double without setting F
I understand this.iansjack wrote:You need to do the multiplication before the division (if using integer arithmetic) to get the correct result. And it’s best to use parentheses to ensure the correct order.whereasCode: Select all
8 * (75 / 100) = 0
The latter is obviously the result you want.Code: Select all
(8 * 75) / 100 = 6
You’re looking for an integer result, so you don’t need floating-point calculations.
He said that I should replace
Code: Select all
m->remap = m->capacity / 4 * 3
Code: Select all
m->remap = m->capacity * 3 * 4
-
- Member
- Posts: 426
- Joined: Tue Apr 03, 2018 2:44 am
Re: Is it possible to use float and double without setting F
No.mrjbom wrote:I understand this.iansjack wrote:You need to do the multiplication before the division (if using integer arithmetic) to get the correct result. And it’s best to use parentheses to ensure the correct order.whereasCode: Select all
8 * (75 / 100) = 0
The latter is obviously the result you want.Code: Select all
(8 * 75) / 100 = 6
You’re looking for an integer result, so you don’t need floating-point calculations.
He said that I should replacewithCode: Select all
m->remap = m->capacity / 4 * 3
which I did not understand.Code: Select all
m->remap = m->capacity * 3 * 4
The suggested code was:
Code: Select all
m->remap = m->capacity * 3 / 4
The other good thing about the code is that the optimiser will turn this all into shifts and adds, so it'll be blazing fast.