trigonometry

LLVM insert intrinsic function Cos

我只是一个虾纸丫 提交于 2019-11-30 23:27:54
I am trying to insert intrinsic cos() function call to LLVM pass. My code in a FunctionPass: std::vector<Type *> arg_type; arg_type.push_back(Type::getFloatTy(getGlobalContext())); Function *fun = Intrinsic::getDeclaration(F.getParent(), Intrinsic::cos, arg_type); CallInst* callInst = CallInst::Create(fun, args, Twine("cos"), (Instruction *)&I); When I leave out last line generated IR is: define i32 @main() nounwind uwtable { entry: ... } declare float @llvm.cos.f32(float) nounwind readonly , but with CallInst included all i get is: 0 opt 0x000000000094f4bf 1 opt 0x000000000094f9c9 2

how to solve cos 90 problem in java? [duplicate]

人盡茶涼 提交于 2019-11-30 22:45:55
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 3 years ago . I have some problems with calculating cosinus 90 in Java using Math.cos function : public class calc{ private double x; private double y; public calc(double x,double y){ this.x=x; this.y=y; } public void print(double theta){ x = x*Math.cos(theta); y = y*Math.sin(theta); System.out.println("cos 90 : "+x); System.out.println("sin 90 : "+y); } public static void main(String[]args){ calc p =

Convert radians to degrees, minutes, and seconds

╄→尐↘猪︶ㄣ 提交于 2019-11-30 20:46:40
问题 I am looking on a way to convert decimals to degrees in C. For instance, the asin() function in C returns a decimal number but I need that number to be in degrees ° minutes ' seconds ". e.g. 1.5 would be 1°30'0" 回答1: The asin function returns radians. There are 2 π radians in a circle. There are 360 degrees in a circle, 60 minutes in a degree, and 60 seconds in a minute. So there are 360*60*60 seconds in a circle. double radians = asin(opposite / hypotenuse); int totalSeconds = (int)round

Trigonometric functions on embedded system

断了今生、忘了曾经 提交于 2019-11-30 19:05:05
sin and cos functions are slow and need a lot of resources to run on embedded systems. How does one calculate sin and cos functions in a more resource-saving and faster way? pavium To calculate a Taylor or Fourier series is always going to be time-consuming. In an embedded system, you should think about lookup tables . There might also be interesting information on the 'Net about how Hewlett-Packard optimised such calculations in their early scientific calculators. I recall seeing such stuff at the time Noldorin A lookup table with interpolation would without doubt be the most efficient

Trigonometric functions on embedded system

自古美人都是妖i 提交于 2019-11-30 16:56:46
问题 sin and cos functions are slow and need a lot of resources to run on embedded systems. How does one calculate sin and cos functions in a more resource-saving and faster way? 回答1: To calculate a Taylor or Fourier series is always going to be time-consuming. In an embedded system, you should think about lookup tables. There might also be interesting information on the 'Net about how Hewlett-Packard optimised such calculations in their early scientific calculators. I recall seeing such stuff at

Special CUDA Double Precision trig functions for SFU

假装没事ソ 提交于 2019-11-30 16:32:32
I was wondering how I would go about using __cos(x) (and respectively __sin(x) ) in the kernel code with CUDA. I looked up in the CUDA manual that there is such a device function however when I implement it the compiler just says that I cannot call a host function in the device. However, I found that there are two sister functions cosf(x) and __cosf(x) the latter of which runs on the SFU and is overall much faster than the original cosf(x) function. The compiler does not complain about the __cosf(x) function of course. Is there a library I'm missing? Am I mistaken about this trig function? As

Reflection? How do I do it?

老子叫甜甜 提交于 2019-11-30 15:51:37
问题 This is over my head, can someone explain it to me better? http://mathworld.wolfram.com/Reflection.html I'm making a 2d breakout fighting game, so I need the ball to be able to reflect when it hits a wall, paddle, or enemy (or a enemy hits it). all their formula's are like: x_1^'-x_0=v-2(v·n^^)n^^. And I can't fallow that. (What does ' mean or x_0? or ^^?) 回答1: The formula for reflection is easier to understand if you think to the geometric meaning of the operation of "dot product". The dot

Calculating rotation along a path

落花浮王杯 提交于 2019-11-30 15:45:57
I am trying to animate an object, let's say its a car. I want it go from point x1,y1,z1 to point x2,y2,z2 . It moves to those points, but it appears to be drifting rather than pointing in the direction of motion. So my question is: how can I solve this issue in my updateframe() event? Could you point me in the direction of some good resources? Thanks. First off how do you represent the road? I recently done exactly this thing and I used Catmull-Rom splines for the road. To orient an object and make it follow the spline path you need to interpolate the current x,y,z position from a t that walks

Reflection? How do I do it?

女生的网名这么多〃 提交于 2019-11-30 15:41:20
This is over my head, can someone explain it to me better? http://mathworld.wolfram.com/Reflection.html I'm making a 2d breakout fighting game, so I need the ball to be able to reflect when it hits a wall, paddle, or enemy (or a enemy hits it). all their formula's are like: x_1^'-x_0=v-2(v·n^^)n^^. And I can't fallow that. (What does ' mean or x_0? or ^^?) The formula for reflection is easier to understand if you think to the geometric meaning of the operation of "dot product". The dot product between two 3d vectors is mathematically defined as <a, b> = ax*bx + ay*by + az*bz but it has a nice

Approximating inverse trigonometric functions

五迷三道 提交于 2019-11-30 14:57:04
问题 I have to implement asin, acos and atan in environment where I have only following math tools: sine cosine elementary fixed point arithmetic (floating point numbers are not available) I also already have reasonably good square root function. Can I use those to implement reasonably efficient inverse trigonometric functions? I don't need too big precision (the floating point numbers have very limited precision anyways), basic approximation will do. I'm already half decided to go with table