Author Topic: C++ library: (sw) fixed point (through overload)  (Read 2300 times)

0 Members and 1 Guest are viewing this topic.

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
C++ library: (sw) fixed point (through overload)
« on: January 14, 2015, 12:55:42 pm »
Quote
git clone https://carlojpisani@code.google.com/p/fixedpoint/

source browse


Code: [Select]
./test2 1.1 1.2
sizeof fixed_t = 12..12 bytes
a    = 1.1
b    = 1.2
a+b  = 2.3
a-b  = -0.1
a*b  = 1.32
-a   = -1.1
b++  = 1.3
a[4] = 1.1000 ... operator precision
a/b = 0.9
a.whole() = 1
is a == b? no
is a != b? yes
is a <  b? yes
is a <= b? yes
is a >  b? no
is a >= b? no

to summarize, this library make possible to use a fixed point type as natural as the floating point type
to make that, it defines a class and then it uses the C++ overload feature in order to redefine operators {+,-,*,/, ...}

enjoy =)
« Last Edit: January 15, 2015, 12:41:06 am by legacy »
 

Offline legacyTopic starter

  • Super Contributor
  • ***
  • !
  • Posts: 4415
  • Country: ch
Re: C++ library: (sw) fixed point (through overload)
« Reply #1 on: January 14, 2015, 12:57:18 pm »
p.s.
it is not a professional code, also a lot of improvements are needed, being warned about that  :-+
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26682
  • Country: nl
    • NCT Developments
Re: C++ library: (sw) fixed point (through overload)
« Reply #2 on: January 15, 2015, 08:34:38 am »
I didn't look at the source but I'm wondering what kind of code the compiler creates to turn the floating point values into integers. That usually is pretty ugly and slow without FPU. But there are some neat tricks here. See:
http://stackoverflow.com/questions/429632/how-to-speed-up-floating-point-to-integer-number-conversion/429812#429812
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf