add morphisms for angle, temperature & real numbers

This commit is contained in:
Michael Sippel 2025-03-18 14:06:05 +01:00
parent 6f85e004b9
commit 65cd0b6853
Signed by: senvas
GPG key ID: F96CF119C34B64A6
3 changed files with 211 additions and 0 deletions

View file

@ -0,0 +1,72 @@
```
#define PHI 6.28318530718
```
morph_angle_as_degrees_to_turns_float ()
Angle ~ Degrees ~ ~ native.Float
--> Angle ~ Turns ~ ~ native.Float
```
*dst = *src / 360.0;
return 0;
```
morph_angle_as_degrees_to_turns_double ()
Angle ~ Degrees ~ ~ native.Double
--> Angle ~ Turns ~ ~ native.Double
```
*dst = *src / 360.0;
return 0;
```
morph_angle_as_turns_to_degrees_float ()
Angle ~ Turns ~ ~ native.Float
--> Angle ~ Degrees ~ ~ native.Float
```
*dst = *src * 360.0;
return 0;
```
morph_angle_as_turns_to_degrees_double ()
Angle ~ Turns ~ ~ native.Double
--> Angle ~ Degrees ~ ~ native.Double
```
*dst = *src * 360.0;
return 0;
```
morph_angle_as_radians_to_turns_float ()
Angle ~ Radians ~ ~ native.Float
--> Angle ~ Turns ~ ~ native.Float
```
*dst = *src / PHI;
return 0;
```
morph_angle_as_radians_to_turns_double ()
Angle ~ Radians ~ ~ native.Double
--> Angle ~ Turns ~ ~ native.Double
```
*dst = *src / PHI;
return 0;
```
morph_angle_as_turns_to_radians_float ()
Angle ~ Turns ~ ~ native.Float
--> Angle ~ Radians ~ ~ native.Float
```
*dst = *src * PHI;
return 0;
```
morph_angle_as_degrees_to_radians_double ()
Angle ~ Turns ~ ~ native.Double
--> Angle ~ Radians ~ ~ native.Double
```
*dst = *src * PHI;
return 0;
```

View file

@ -0,0 +1,105 @@
```
#include <stdio.h>
```
morph_real_as_decimalstr_to_float ()
~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
--> ~ native.Float
```
sscanf(src, "%f", dst);
return 0;
```
morph_real_as_decimalstr_to_double ()
~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
--> ~ native.Double
```
sscanf(src, "%lf", dst);
return 0;
```
morph_real_as_float_to_decimalstr ()
~ native.Float
--> ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
```
sprintf(dst, "%f", *src);
return 0;
```
morph_real_as_double_to_decimalstr ()
~ native.Double
--> ~ <PosInt 10 BigEndian> ~ <Seq~<ValueTerminated 0> <Digit 10>~Char~Ascii~x86.UInt8>
```
sprintf(dst, "%f", *src);
return 0;
```
morph_real_as_float_to_double ()
~ native.Float
--> ~ native.Double
```
*dst = *src;
return 0;
```
morph_real_as_double_to_float ()
~ native.Double
--> ~ native.Float
```
fprintf(stderr, "Warning: morphin Double -> Float. Precision loss!");
*dst = *src;
return 0;
```
morph_real_as_u64_to_float ()
~ ~ x86.UInt64
--> ~ native.Float
```
fprintf(stderr, "Warning: morphin UInt64 -> Float. Precision loss!");
*dst = *src;
return 0;
```
morph_real_as_u64_to_double ()
~ ~ x86.UInt64
--> ~ native.Double
```
fprintf(stderr, "Warning: morphin UInt64 -> Double. Precision loss!");
*dst = *src;
return 0;
```
morph_real_as_quantized_linear_to_float (Begin: , End: , Steps: )
~ <QuantizedLinear Begin End Steps> ~ ~ x86.UInt64
--> ~ native.Float
```
*dst = (float)Begin + ( *src * ((float)End - (float)Begin) ) / (float)Steps;
return 0;
```
morph_real_as_float_to_quantized_linear (Begin: , End: , Steps: )
~ native.Float
--> ~ <QuantizedLinear Begin End Steps> ~ ~ x86.UInt64
```
*dst = ((*src - (float)Begin) * (float)Steps) / ((float)End - (float)Begin);
return 0;
```
morph_real_as_quantized_linear_to_double (Begin: , End: , Steps: )
~ <QuantizedLinear Begin End Steps> ~ ~ x86.UInt64
--> ~ native.Double
```
*dst = (double)Begin + ( *src * ((double)End - (double)Begin) ) / (double)Steps;
return 0;
```
morph_real_as_double_to_quantized_linear (Begin: , End: , Steps: )
~ native.Double
--> ~ <QuantizedLinear Begin End Steps> ~ ~ x86.UInt64
```
*dst = ((*src - (double)Begin) * (double)Steps) / ((double)End - (double)Begin);
return 0;
```

View file

@ -0,0 +1,34 @@
```
```
morph_celsius_to_kelvin ()
Temperature ~ Celsius ~ ~ native.Float
--> Temperature ~ Kelvin ~ ~ native.Float
```
*dst = *src + 273.15;
return 0;
```
morph_kelvin_to_celsius ()
Temperature ~ Kelvin ~ ~ native.Float
--> Temperature ~ Celsius ~ ~ native.Float
```
*dst = *src - 273.15;
return 0;
```
morph_celsius_to_fahrenheit ()
Temperature ~ Celsius ~ ~ native.Float
--> Temperature ~ Fahrenheit ~ ~ native.Float
```
*dst = (*src * 9.0 / 5.0) + 32.0;
return 0;
```
morph_fahrenheit_to_celsius ()
Temperature ~ Fahrenheit ~ ~ native.Float
--> Temperature ~ Celsius ~ ~ native.Float
```
*dst = (*src - 32.0) * 5.0 / 9.0;
return 0;
```