Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
math problem for experts
#4
I had trouble making this an attachment, so here is the Linux code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
double c = cos((90.0/360.0) * (2.0 * M_PI))
double s = sin(0)
printf("cos(90) = %lf, sin(0) = %lf\n", c, s)
return EXIT_SUCCESS
}

/*
To compile and run:
gcc trig_test.c -o trig_test
chmod +x trig_test
./trig_test

Output is:
cos(90) = 0.00000, sin(0) = 0.000000

So your cpp compiler is wrong too?

My concern is how many other angles might I have to treat specially?

If I rotate the point (100.0, 0.0, 0.0) by 90 degrees, the resulting x value is 6.<15 bits>e-15 away from the correct value.
So an error band of 10**(-14) might not be appropriate in such a case.

One would think that:

(1) Python developers would save themselves some effort by just using the gcc math library functions (at least for non bignums),
and that the gcc functions would save processing time by using available floating point hardware, which on my machines is 64 bits.

(2) As it appears they are not, the Python developers could save processing time by special casing multiples of pi/2 (90 degrees),
which are the well known maxima, minima and zero crossing points of the sin and cos functions,
instead of blindly evaluating some supposedly converging power series.
Reply


Messages In This Thread
math problem for experts - by miltmobley - Jul-08-2023, 08:24 PM
RE: math problem for experts - by jefsummers - Jul-08-2023, 10:12 PM
RE: math problem for experts - by deanhystad - Jul-08-2023, 11:13 PM
RE: math problem for experts - by miltmobley - Jul-09-2023, 12:50 AM
RE: math problem for experts - by deanhystad - Jul-09-2023, 02:16 AM
RE: math problem for experts - by Gribouillis - Jul-09-2023, 07:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  math.log versus math.log10 stevendaprano 10 2,539 May-23-2022, 08:59 PM
Last Post: jefsummers
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 3,876 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  Problem with the math.sin(x) function Carson147 4 3,018 Feb-21-2019, 05:12 PM
Last Post: Carson147
  matrices math problem lokoprof 1 2,253 Aug-27-2018, 07:48 PM
Last Post: perfringo
  Math problem python Dhaval 1 2,984 Jun-05-2017, 10:28 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020