Go to Post I think I need a bigger cup of coffee.... - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-01-2007, 11:16
nirhaim1942 nirhaim1942 is offline
Registered User
None #1942
 
Join Date: Jan 2007
Location: IL
Posts: 2
nirhaim1942 is an unknown quantity at this point
sin() function problem

Hello everybody,

I have some problems in programming the controller.

when i tried to printf() the result of sin() function the terminal dosen't show nothing.

the code's lines:
==================
float result,angle;
float PI = 3.14;

angle=30.0;
result= sin (angle*PI/180);
printf("the sine of angle %f is %f",angle,result);

=============

if somebody knows how to reslove this problem it will be great.

thanks
Nir Haim
TEAM 1942.
  #2   Spotlight this post!  
Unread 22-01-2007, 11:20
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,722
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: sin() function problem

Placing "\r" at the end of your printf string will cause it to print.
Did you use: #include <stdio.h>

Finally, "%f" is not supported by printf on this compiler and printf will not take floats as arguments, so you have to play a trick to print it.

Standard Disclaimer: Floating point is not directly supported on the PIC, so it's bulky and slow. Avoid it if you can.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 22-01-2007 at 11:23.
  #3   Spotlight this post!  
Unread 22-01-2007, 11:43
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: sin() function problem

Try this:

Code:
printf("the sine of angle %d is %d\r",(int) angle,(int) (result * 1000.0));
Note that "result" will be a number between 0 and 1 which will truncate to 0 or 1 when type cast to an integer. Multiplying by 1000 will display a number between 0 and 1000.

Also, I echo Mark's disclaimer. Floating point arithmetic is extremely inefficient.

Mike
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.h sin syntax error Sykan Programming 8 21-01-2007 09:26
Arcade Function gabrielse Programming 1 08-02-2006 00:49
Limit_Mix() Function EricWilliams Programming 2 27-07-2005 23:19
Sin, Cos, Atan the_undefined Programming 3 16-02-2005 02:32
FreeLibrary() Function Raven_Writer Programming 0 09-08-2003 15:39


All times are GMT -5. The time now is 10:43.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi