Atmega Divide By Zero Error
Contents |
(read only) > Software > Syntax & Programs > no DIVIDE BY ZERO error? Print Go Down Pages: [1] Topic: no DIVIDE BY ZERO divide by zero error sql error?(Read 3630 times) previous topic - next topic ahdavidson Sr. Member Posts: divide by zero error java 250 Karma: 6[add] Andrew Davidson no DIVIDE BY ZERO error? Sep 16, 2009, 05:08 am Having forgotten divide by zero error encountered some of the basic rules of C data types tonight while working on a simple math calculation, I was doing some investigation into division operations.After a lot of debugging, I
Excel Divide By Zero Error Hide
gave myself a good cranial dent with the heel of my hand and my memory was refreshed on the rules of int/long sizes and math operations.The sample program below illustrates what is clearly stated here: http://arduino.cc/en/Reference/Arithmetic. Output is also below.The moral of the story is that type casting is just another math operation, and it follows the normal associative divide by zero error encountered in stored procedure laws for evaluation.But, back in the last century when I learned math and computer science, I think we were taught that division by zero should result in a program error, regardless of data type. Did they change that rule somewhere along the way and I miss the memo?So, my question is, why does the first iteration of the loop give either +/- 1 for a result instead of an error?Code: [Select]/* IntMath
Andy Davidson
This program is intended to evaluate the function
y = 60000 / x
over the range of x = 0 to 6000 in increments of 100.
Only c2 and c4 produce the right result, demonstrating that
the default type for integer constants is int, and that
type casting is just another math operation, which
follows the normal associative laws for evaluation.
*/
const long c1 = 60 * 1000;
const long c2 = 60 * long (1000);
const long c3 = long (6
Display results as threads More... Useful Searches Recent Posts Menu Forums Forums Quick Links Search Forums Recent Posts Menu Log in Sign up AnandTech Forums: Technology, Hardware, Software, and Deals Forums > Social > Off Topic > Don't ever divide by divide by zero error encountered. in sql server zero on AVR atmega32! Discussion in 'Off Topic' started by her209, Sep 30, 2011. her209 No
Divide By Zero Error Encountered In Sql Server 2012
Lifer Joined: Oct 11, 2000 Messages: 56,361 Likes Received: 0 http://www.youtube.com/watch?v=mZ7pUADoo58 #1 her209, Sep 30, 2011 Wyndru Diamond Member Joined: Apr 9,
Divide By Zero Error Encountered. The Statement Has Been Terminated
2009 Messages: 7,319 Likes Received: 0 Haha, reminds me of those old tomshardware vids where they removed the heat sink and stress test those old amd cpus with the exposed die. #2 Wyndru, Sep 30, 2011 SunnyD Belgian Waffler http://forum.arduino.cc/index.php?topic=42391.0 Joined: Jan 2, 2001 Messages: 32,543 Likes Received: 4 Apparently AVR atmega's are poorly designed. There's tons of their chips that can't handle common error situations and fail... catastrophically. #3 SunnyD, Sep 30, 2011 Drako Lifer Joined: Jun 9, 2007 Messages: 10,090 Likes Received: 5 Meh, that's got to be fake. The dude probably applied 12 volts to the power pins. #4 Drako, Sep 30, 2011 alkemyst No Lifer Joined: Feb 13, 2001 Messages: 83,988 Likes Received: https://forums.anandtech.com/threads/dont-ever-divide-by-zero-on-avr-atmega32.2195342/ 4 Divide by zero is total fail #5 alkemyst, Sep 30, 2011 Lithium381 Lifer Joined: May 12, 2001 Messages: 12,465 Likes Received: 1 oops #6 Lithium381, Sep 30, 2011 (You must log in or sign up to post here.) Show Ignored Content Your name or email address: Do you already have an account? No, create an account now. Yes, my password is: Forgot your password? Stay logged in Sign up now! New Posts Apple Music: F*** off. I don't want you on my iPhone. Latest: Eug, Oct 1, 2016 at 10:40 AM Mobile Devices & Gadgets ℒổℕḋổℕ=[ in San Diego ]=(( +91-74 24 99 91 86 )) LOVE PROBLEM SOLUTION BA BA JI Latest: svdzfzxxcvxvc, Oct 1, 2016 at 10:40 AM Motherboards Can someone explain to me why NAFTA and TPP are bad? Latest: Brainonska511, Oct 1, 2016 at 10:39 AM Politics and News ℒổℕḋổℕ=[ in Los Angeles ]=(( +91-74 24 99 91 86 )) LOVE PROBLEM SOLUTION BA BA JI Latest: svdzfzxxcvxvc, Oct 1, 2016 at 10:39 AM Motherboards [฿Ѧᵬ₳]+91-7424999186 » To Get RiD oF All problem in 72hours in † greece-germany † Latest: svdzfzxxcvxvc, Oct 1, 2016 at 10:37 AM Motherboards AnandTech Forums: Technology, Hardware, Software, and Deals Forums > Social > Off Topic > Toggle Width Style forums.anandtech.com - UI.X Home Contact Us Help Terms and Rules Privacy Policy Top Copyright © 2016 Purch Group, Inc. All Rights Reserved Theme
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with http://stackoverflow.com/questions/25702098/gcc-division-by-zero us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up gcc: division by zero up vote 5 down vote favorite 1 I am getting division by zero error at this line: if (tim2_st_ovf < T2_PREK_250) These values are defines like this: volatile uint8_t tim2_st_ovf = 0; #define T2_PREK_250 ((250 * (F_CPU / divide by 1000)) / ((UINT8_MAX + 1) * 1024)) #define F_CPU 16000000UL And UINT8_MAX equals to 255. Why am I getting this? I calculated it several times on calculator and am getting ~15. Also, if I change 1024 to 1023 it doesnt show any error. c gcc-warning avr-gcc share|improve this question edited Sep 6 '14 at 16:13 John Kugelman 173k36306384 asked Sep 6 '14 at 16:05 user1806687 405317 Please post an sscce.org (including the main function). –pts Sep 6 '14 at 16:11 add a comment| divide by zero 1 Answer 1 active oldest votes up vote 7 down vote accepted ((UINT8_MAX + 1) * 1024) may become 0, because UINT8_MAX + 1 is usually 256, and 256 * 1024 is 0 modulo 216. So if sizeof(int) == 2 on your achitecture, then you get 0. On the typical modern desktop architectures with GCC, sizeof(int) == 4, and you wouldn't get the division by 0. To fix it, replace 1024 with 1024UL. That will work, because unsigned long is guaranteed to go up to 4294967295. (Thanks to Pascal Cuoq for explaining it.) share|improve this answer edited Sep 6 '14 at 16:41 answered Sep 6 '14 at 16:07 pts 26.1k959103 Awesome, thanks for the solution and the explanation! I will accept the anwser as soon as I can. –user1806687 Sep 6 '14 at 16:15 I'd say this is backed up by the fact that 16000000 is marked with UL in the next line, whereas this would comfortably fit inside a 32-bit integer (this also implies that ULL would indeed be overkill on this platform). –Dave Sep 6 '14 at 16:16 1 unsigned long is guaranteed to go up to 4294967295, so there is no way that replacing 1024 with 1024UL can fail to work. –Pascal Cuoq Sep 6 '14 at 16:32 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name E
be down. Please try the request again. Your cache administrator is webmaster. Generated Sat, 01 Oct 2016 14:36:19 GMT by s_hv987 (squid/3.5.20)