Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SE_TRUE_NODE returns different values on chrome and windows #13

Open
ynvgib opened this issue Jan 16, 2024 · 6 comments
Open

SE_TRUE_NODE returns different values on chrome and windows #13

ynvgib opened this issue Jan 16, 2024 · 6 comments
Assignees

Comments

@ynvgib
Copy link

ynvgib commented Jan 16, 2024

I am using these functions in the code to return the SUN and TRUE_NODE (north node):

CoordinatesWithSpeed posSun, posNorthnode;
posSun = Sweph.swe_calc_ut(jd, HeavenlyBody.SE_SUN, SwephFlag.SEFLG_SWIEPH);
posNorthnode = Sweph.swe_calc_ut(jd, HeavenlyBody.SE_TRUE_NODE, SwephFlag.SEFLG_SWIEPH);
double printNorthNode = posNorthnode.longitude;
double printSun = posSun.longitude;
print ("Sun: $printSun");
print ("North Node is: $printNorthNode");

I am using this ephemeris:

await Sweph.init(epheAssets: [
    "packages/sweph/assets/ephe/seas_18.se1",
  ]);

There is a CLEAR DIFFERENCE in the TRUE_NODE, but also a slight one in the SUN.

these are the printed times and data:

===
EXAMPLE 1:
CHROME:

time is 2024-01-16 07:30:00.000
jd time is 2460325.8125
Sun: 295.6463757021934
North Node is: 19.581430913105162

WINDOWS:

flutter: time is 2024-01-16 07:30:00.000
flutter: jd time is 2460325.8125
flutter: Sun: 295.6463757021932
flutter: North Node is: 19.582942888102373

==============
EX.2
CHROME:

time is 1983-10-03 13:15:00.000
jd time is 2445611.0520833335
Sun: 189.75635745500242
North Node is: 78.61301401943668

WINDOWS:

flutter: time is 1983-10-03 13:15:00.000
flutter: jd time is 2445611.0520833335
flutter: Sun: 189.75635745500242
flutter: North Node is: 78.61875087620729

Ex. 3

CHROME:
time is 1978-05-21 00:30:00.000
jd time is 2443649.5208333335
Sun: 59.61371667811282
North Node is: 184.55327434949876

WINDOWS:
flutter: time is 1978-05-21 00:30:00.000
flutter: jd time is 2443649.5208333335
flutter: Sun: 59.61371667811284
flutter: North Node is: 184.54967016401204

=====

I am using Android Studio Flamingo | 2022.2.1 Patch 2
and flutter:
PS C:\Users\val\projects\flutter\finallyicanlearn> flutter --version
Flutter 3.16.0-10.0.pre • channel master • https://github.com/flutter/flutter.git
Framework • revision c0d19ca561 (3 months ago) • 2023-10-11 23:33:07 -0400
Engine • revision d00fabf0b9
Tools • Dart 3.3.0 (build 3.3.0-14.0.dev) • DevTools 2.28.1

SWEPH: sweph 2.10.3+16

@vm75
Copy link
Owner

vm75 commented Jan 19, 2024

Thanks for reporting this. I will look into it and get back.

@vm75 vm75 self-assigned this Jan 19, 2024
@vm75
Copy link
Owner

vm75 commented Jan 21, 2024

@ynvgib
I do see some difference in my setup, but not as much as you, especially for example 2. Android Studio version should not matter as Android isn't being tested. Having said that, presently WASM is 32-bit, whereas FFI is 64-bit. That may affect some floating point calculations.

Here is the code I added to the example:
// var time = DateTime(2024, 01, 16, 7, 30); // 2024-01-16 07:30:00.000
// var time = DateTime(1983, 10, 3, 13, 15); // 1983-10-03 13:15:00.000
var time = DateTime(1978, 05, 21, 00, 30); // 1978-05-21 00:30:00.000
double jd = Sweph.swe_julday(time.year, time.month, time.day,
time.hour + time.minute / 60, CalendarType.SE_GREG_CAL);

CoordinatesWithSpeed posSun, posNorthnode;
posSun = Sweph.swe_calc_ut(jd, HeavenlyBody.SE_SUN, SwephFlag.SEFLG_SWIEPH);
posNorthnode =
    Sweph.swe_calc_ut(jd, HeavenlyBody.SE_TRUE_NODE, SwephFlag.SEFLG_SWIEPH);
double printNorthNode = posNorthnode.longitude;
double printSun = posSun.longitude;
debugPrint("time is $time");
debugPrint("jd time is $jd");
debugPrint("Sun: $printSun");
debugPrint("North Node is: $printNorthNode");

my result:

CHROME
time is 2024-01-16 07:30:00.000
jd time is 2460325.8125
Sun: 295.6463757021934
North Node is: 19.581430913105162

Windows
flutter: time is 2024-01-16 07:30:00.000
flutter: jd time is 2460325.8125
flutter: Sun: 295.6463757021932
flutter: North Node is: 19.581430913105162

CHROME
time is 1983-10-03 13:15:00.000
jd time is 2445611.0520833335
Sun: 189.75635745500242
North Node is: 78.61301401943668

Windows
flutter: time is 1983-10-03 13:15:00.000
flutter: jd time is 2445611.0520833335
flutter: Sun: 189.75635745500242
flutter: North Node is: 78.61301401943668

CHROME
time is 1978-05-21 00:30:00.000
jd time is 2443649.5208333335
Sun: 59.61371667811282
North Node is: 184.55327434949876

Windows
flutter: time is 1978-05-21 00:30:00.000
flutter: jd time is 2443649.5208333335
flutter: Sun: 59.61371667811284
flutter: North Node is: 184.5532743488916

@ynvgib
Copy link
Author

ynvgib commented Jan 25, 2024 via email

@ynvgib
Copy link
Author

ynvgib commented Jan 26, 2024

I created a clean project with minimal code just to check:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Sweph.init(epheAssets: [
    "packages/sweph/assets/ephe/seas_18.se1",
  ]);

  DateTime now = DateTime.now();
  //now = DateTime(1983, 10, 3, 13, 15);
  now = DateTime(1978, 5, 21, 00, 30);
  final CoordinatesWithSpeed posSun, posNorthnode;
  final secondsInMinutes = now.second / 60;
  final minutesInHours = (now.minute + secondsInMinutes) / 60;
  final hours = now.hour + minutesInHours;
  final jd = Sweph.swe_julday(
      now.year, now.month, now.day, hours, CalendarType.SE_GREG_CAL);

  print("time is $now");
  print("jd time is $jd");

  posSun = Sweph.swe_calc_ut(jd, HeavenlyBody.SE_SUN, SwephFlag.SEFLG_SWIEPH);
  posNorthnode =
      Sweph.swe_calc_ut(jd, HeavenlyBody.SE_TRUE_NODE, SwephFlag.SEFLG_SWIEPH);
//idk
  double printNorthNode = posNorthnode.longitude;
  double printSun = posSun.longitude;
  print ("Sun: $printSun");
  print ("North Node is: $printNorthNode");

  runApp(const MyApp());
}

and the result were:

_chrome
1
time is 1983-10-03 13:15:00.000
jd time is 2445611.0520833335
Sun: 189.75635745500242
North Node is: 78.61301401943668

===
2
windows

flutter: time is 1983-10-03 13:15:00.000
flutter: jd time is 2445611.0520833335
flutter: Sun: 189.75635745500242
flutter: North Node is: 78.61301401943668

==============
1
chrome

time is 1978-05-21 00:30:00.000
jd time is 2443649.5208333335
Sun: 59.61371667811282
North Node is: 184.55327434949876

2
win

flutter: time is 1978-05-21 00:30:00.000
flutter: jd time is 2443649.5208333335
flutter: Sun: 59.61371667811284
flutter: North Node is: 184.5532743488916

====_

so the "glitch" on the northnode turns minor to none
1: North Node is: 78.61301401943668
2: North Node is: 78.61301401943668

1: North Node is: 184.55327434 then 949876
2: North Node is: 184.55327434 then 88916

Sun is pretty much equal.

I don't really know where that bug comes from.
Maybe some memory glitch in the "complex" code which seems not to happen on the "simple" code.
I don't know.

@jimmyff
Copy link

jimmyff commented Jun 14, 2024

It could well be to do with with javascript floating-point precision limitations? I had a similar issue years ago with a game related project.

Perhaps you could make use of decimal.js or scale the high precision values to integers for calculations and then scale back down to original units?

@ynvgib
Copy link
Author

ynvgib commented Jun 14, 2024

I don't know.

It is in flutter so I found this flutter (dart) package
https://pub.dev/packages/decimal

However, the calculation right on Windows
but false on Web and Android.

I'm not sure about the 32bit or 64 bit difference, or the web/android vs windows calculation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants