##// END OF EJS Templates
fixpoint: implementacion de numero de punto fijo
aaguilar -
r202:203
parent child
Show More
@@ -0,0 +1,127
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3 <storageModule moduleId="org.eclipse.cdt.core.settings">
4 <cconfiguration id="cdt.managedbuild.config.gnu.exe.debug.726614945">
5 <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.debug.726614945" moduleId="org.eclipse.cdt.core.settings" name="Debug">
6 <externalSettings/>
7 <extensions>
8 <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
9 <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
10 <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
11 <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
12 <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
13 <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
14 </extensions>
15 </storageModule>
16 <storageModule moduleId="cdtBuildSystem" version="4.0.0">
17 <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.debug.726614945" name="Debug" parent="cdt.managedbuild.config.gnu.exe.debug">
18 <folderInfo id="cdt.managedbuild.config.gnu.exe.debug.726614945." name="/" resourcePath="">
19 <toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.1187435907" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
20 <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.588259323" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
21 <builder buildPath="${workspace_loc:/fixpoint}/Debug" id="cdt.managedbuild.target.gnu.builder.exe.debug.142867279" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
22 <tool id="cdt.managedbuild.tool.gnu.archiver.base.1340458624" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
23 <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1123809143" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
24 <option id="gnu.cpp.compiler.exe.debug.option.optimization.level.1352962247" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
25 <option id="gnu.cpp.compiler.exe.debug.option.debugging.level.602612294" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
26 <option id="gnu.cpp.compiler.option.dialect.std.2006213990" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" value="gnu.cpp.compiler.dialect.default" valueType="enumerated"/>
27 <option id="gnu.cpp.compiler.option.other.other.377703301" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0" valueType="string"/>
28 <option id="gnu.cpp.compiler.option.other.verbose.88007056" name="Verbose (-v)" superClass="gnu.cpp.compiler.option.other.verbose" value="false" valueType="boolean"/>
29 <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1358658388" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
30 </tool>
31 <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.2093971068" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
32 <option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.exe.debug.option.optimization.level.1595578750" name="Optimization Level" superClass="gnu.c.compiler.exe.debug.option.optimization.level" valueType="enumerated"/>
33 <option id="gnu.c.compiler.exe.debug.option.debugging.level.1789087258" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
34 <option id="gnu.c.compiler.option.misc.other.1606297075" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 " valueType="string"/>
35 <option id="gnu.c.compiler.option.misc.verbose.1010982186" name="Verbose (-v)" superClass="gnu.c.compiler.option.misc.verbose" value="false" valueType="boolean"/>
36 <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1171595764" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
37 </tool>
38 <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.2034761377" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug"/>
39 <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.1694084085" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug">
40 <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1839555914" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
41 <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
42 <additionalInput kind="additionalinput" paths="$(LIBS)"/>
43 </inputType>
44 </tool>
45 <tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.49081962" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
46 <inputType id="cdt.managedbuild.tool.gnu.assembler.input.953234959" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
47 </tool>
48 </toolChain>
49 </folderInfo>
50 </configuration>
51 </storageModule>
52 <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
53 </cconfiguration>
54 <cconfiguration id="cdt.managedbuild.config.gnu.exe.release.627789590">
55 <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.627789590" moduleId="org.eclipse.cdt.core.settings" name="Release">
56 <externalSettings/>
57 <extensions>
58 <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
59 <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
60 <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
61 <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
62 <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
63 <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
64 </extensions>
65 </storageModule>
66 <storageModule moduleId="cdtBuildSystem" version="4.0.0">
67 <configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.exe.release.627789590" name="Release" parent="cdt.managedbuild.config.gnu.exe.release">
68 <folderInfo id="cdt.managedbuild.config.gnu.exe.release.627789590." name="/" resourcePath="">
69 <toolChain id="cdt.managedbuild.toolchain.gnu.exe.release.203535649" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.exe.release">
70 <targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.release.1705051134" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.release"/>
71 <builder buildPath="${workspace_loc:/fixpoint}/Release" id="cdt.managedbuild.target.gnu.builder.exe.release.968018891" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.exe.release"/>
72 <tool id="cdt.managedbuild.tool.gnu.archiver.base.1233091539" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
73 <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.217129682" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.release">
74 <option id="gnu.cpp.compiler.exe.release.option.optimization.level.853294042" name="Optimization Level" superClass="gnu.cpp.compiler.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
75 <option id="gnu.cpp.compiler.exe.release.option.debugging.level.819444220" name="Debug Level" superClass="gnu.cpp.compiler.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
76 <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.323758775" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
77 </tool>
78 <tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.release.1379716" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.release">
79 <option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.exe.release.option.optimization.level.1394624330" name="Optimization Level" superClass="gnu.c.compiler.exe.release.option.optimization.level" valueType="enumerated"/>
80 <option id="gnu.c.compiler.exe.release.option.debugging.level.630382415" name="Debug Level" superClass="gnu.c.compiler.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
81 <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.45831321" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
82 </tool>
83 <tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.1178554217" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release"/>
84 <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.release.541725393" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.release">
85 <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1118856248" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
86 <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
87 <additionalInput kind="additionalinput" paths="$(LIBS)"/>
88 </inputType>
89 </tool>
90 <tool id="cdt.managedbuild.tool.gnu.assembler.exe.release.486187560" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.release">
91 <inputType id="cdt.managedbuild.tool.gnu.assembler.input.610155476" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
92 </tool>
93 </toolChain>
94 </folderInfo>
95 </configuration>
96 </storageModule>
97 <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
98 </cconfiguration>
99 </storageModule>
100 <storageModule moduleId="cdtBuildSystem" version="4.0.0">
101 <project id="fixpoint.cdt.managedbuild.target.gnu.exe.1493244722" name="Executable" projectType="cdt.managedbuild.target.gnu.exe"/>
102 </storageModule>
103 <storageModule moduleId="scannerConfiguration">
104 <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
105 <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.726614945;cdt.managedbuild.config.gnu.exe.debug.726614945.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.1123809143;cdt.managedbuild.tool.gnu.cpp.compiler.input.1358658388">
106 <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
107 </scannerConfigBuildInfo>
108 <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.627789590;cdt.managedbuild.config.gnu.exe.release.627789590.;cdt.managedbuild.tool.gnu.c.compiler.exe.release.1379716;cdt.managedbuild.tool.gnu.c.compiler.input.45831321">
109 <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
110 </scannerConfigBuildInfo>
111 <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.release.627789590;cdt.managedbuild.config.gnu.exe.release.627789590.;cdt.managedbuild.tool.gnu.cpp.compiler.exe.release.217129682;cdt.managedbuild.tool.gnu.cpp.compiler.input.323758775">
112 <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
113 </scannerConfigBuildInfo>
114 <scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.exe.debug.726614945;cdt.managedbuild.config.gnu.exe.debug.726614945.;cdt.managedbuild.tool.gnu.c.compiler.exe.debug.2093971068;cdt.managedbuild.tool.gnu.c.compiler.input.1171595764">
115 <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
116 </scannerConfigBuildInfo>
117 </storageModule>
118 <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
119 <storageModule moduleId="refreshScope" versionNumber="2">
120 <configuration configurationName="Debug">
121 <resource resourceType="PROJECT" workspacePath="/fixpoint"/>
122 </configuration>
123 <configuration configurationName="Release">
124 <resource resourceType="PROJECT" workspacePath="/fixpoint"/>
125 </configuration>
126 </storageModule>
127 </cproject>
@@ -0,0 +1,27
1 <?xml version="1.0" encoding="UTF-8"?>
2 <projectDescription>
3 <name>fixpoint</name>
4 <comment></comment>
5 <projects>
6 </projects>
7 <buildSpec>
8 <buildCommand>
9 <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10 <triggers>clean,full,incremental,</triggers>
11 <arguments>
12 </arguments>
13 </buildCommand>
14 <buildCommand>
15 <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16 <triggers>full,incremental,</triggers>
17 <arguments>
18 </arguments>
19 </buildCommand>
20 </buildSpec>
21 <natures>
22 <nature>org.eclipse.cdt.core.cnature</nature>
23 <nature>org.eclipse.cdt.core.ccnature</nature>
24 <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25 <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26 </natures>
27 </projectDescription>
@@ -0,0 +1,121
1 /*
2 * fixpoint<T>.h
3 *
4 * Created on: Feb 24, 2015
5 * Author: aras
6 */
7
8 #ifndef FIXPOINT_H_
9 #define FIXPOINT_H_
10
11 #include <inttypes.h>
12 #include <math.h>
13 #include <typeinfo>
14 #include <cstdio>
15
16
17
18
19 template<class T>
20 class fixpoint {
21
22 private:
23 uint8_t factor;
24 T value;
25
26 public:
27 fixpoint<T>(const fixpoint<T>& fp){factor=fp.factor;value=fp.value;};
28 fixpoint<T>(uint8_t dec);
29 fixpoint<T>(uint8_t dec,T num);
30
31 void set_from_float(float num){value=T(num*(1<<factor));}
32 void set(T val){value = val;}
33 float tofloat();
34
35
36 friend inline fixpoint<T> operator-(const fixpoint<T> &num1, const fixpoint<T> &num2){
37 return fixpoint<T>(num1.factor,num1.value-num2.value);
38 }
39 friend inline fixpoint<T> operator+(const fixpoint<T> &num1, const fixpoint<T> &num2){
40 return fixpoint<T>(num1.factor,num1.value+num2.value);
41 }
42 friend inline fixpoint<T> operator*(const fixpoint<T> &num1, const fixpoint<T> &num2){
43 int64_t aux = (int64_t(num1.value)*int64_t(num2.value))>>num1.factor;
44 return fixpoint<T>(num1.factor,T(aux));
45 }
46 friend inline fixpoint<T> operator/(const fixpoint<T> &num1, const fixpoint<T> &num2){
47 int64_t aux = (int64_t(num1.value)<<num1.factor);
48 return fixpoint<T>(num1.factor,aux/num2.value);
49 }
50
51
52 //fixpoint<T>& operator= ( const fixpoint<T>& );
53
54 inline fixpoint<T> power();
55 inline fixpoint<T> sqroot();
56 };
57
58
59 //template<class T>
60 //fixpoint<T> & fixpoint<T>::operator= ( fixpoint<T> ){
61 //
62 //}
63
64
65
66
67 template<class T>
68 fixpoint<T>::fixpoint(uint8_t dec){
69 factor=dec;
70 value=0;
71 }
72
73 template<class T>
74 fixpoint<T>::fixpoint(uint8_t dec,T num){
75 factor=dec;
76 value=num;
77 }
78
79
80 template<class T>
81 float fixpoint<T>::tofloat(){
82 return float(value)/(1<<factor);
83 }
84
85 template<class T>
86 fixpoint<T> fixpoint<T>::power(){
87 int64_t aux = (int64_t(value)*int64_t(value))>>factor;
88 return fixpoint<T>(aux);
89 }
90
91 template<class T>
92 fixpoint<T> fixpoint<T>::sqroot(){
93 T aux = sqrt(value);
94 return fixpoint<T>(aux<<(factor/2));
95 }
96
97
98
99 typedef fixpoint<int32_t> num32;
100 typedef fixpoint<int64_t> num64;
101
102
103 class fix1912:public num32{
104 public:
105 fix1912():num32(12){};
106 fix1912(int32_t num):num32(12,num){};
107 };
108
109 class fix0922:public num32{
110 public:
111 fix0922():num32(22){};
112 fix0922(int32_t num):num32(22,num){};
113 };
114
115 class fix4320:public num64{
116 public:
117 fix4320():num64(20){};
118 fix4320(int64_t num):num64(20,num){};
119 };
120
121 #endif /* FIXPOINT_H_ */
@@ -0,0 +1,31
1 /*
2 * fixpoint_test.cpp
3 *
4 * Created on: Feb 24, 2015
5 * Author: aras
6 */
7
8 #include "fixpoint.h"
9
10
11 int main(){
12
13 fix1912 A;
14 fix1912 B;
15 A.set_from_float(2);
16 B.set_from_float(5);
17 fix1912 C;
18 C=A*B;
19 C.power();
20 // N44_20 A1;
21 // N44_20 B1;
22 // A1.set_from_float(2);
23 // B1.set_from_float(5);
24 //
25 // N44_20 C1 = (A1*B1).power();
26
27 printf("float valout: %f\n",-2.0*500.0);
28 printf("C valout: %f\n",C.tofloat());
29 // printf("C1 valout: %f",C1.tofloat());
30 return 0;
31 }
General Comments 0
You need to be logged in to leave comments. Login now