seed7-users Mailing List for Seed7 (Page 4)
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
|
Feb
(9) |
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
(4) |
Aug
|
Sep
(4) |
Oct
(4) |
Nov
|
Dec
(1) |
2011 |
Jan
(2) |
Feb
|
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
(2) |
Aug
(6) |
Sep
(7) |
Oct
(3) |
Nov
(10) |
Dec
(4) |
2013 |
Jan
(2) |
Feb
|
Mar
(2) |
Apr
|
May
(1) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
(5) |
Nov
|
Dec
(1) |
2014 |
Jan
(1) |
Feb
|
Mar
|
Apr
(1) |
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(4) |
Nov
(1) |
Dec
(1) |
2015 |
Jan
(2) |
Feb
(2) |
Mar
(2) |
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
|
2016 |
Jan
|
Feb
(3) |
Mar
(2) |
Apr
|
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2017 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2018 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
|
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
2021 |
Jan
(2) |
Feb
(6) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(12) |
Oct
(4) |
Nov
(17) |
Dec
(3) |
2022 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
(2) |
May
|
Jun
(17) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2023 |
Jan
|
Feb
(1) |
Mar
(4) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(1) |
Nov
|
Dec
|
2024 |
Jan
|
Feb
(5) |
Mar
(7) |
Apr
|
May
|
Jun
|
Jul
(4) |
Aug
(12) |
Sep
|
Oct
|
Nov
|
Dec
(2) |
2025 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Zaakari <Za...@pr...> - 2021-11-13 16:54:46
|
Hey Thomas, I ran into a strange error today: when I make a function to return a 2-dimensional string array, seed7 throws a "Match for ... failed" error. I can make local multi-dimensional arrays without issue, it's just when I try to use them as the result of a function that an error is raised. I'm guessing this happens with all types of multi-dimensional arrays--though I only tested string and integer arrays. I've attached an example program in which I have a local 2-dimensional string array that I loop through, echoing its contents. But if you un-comment the "test_multiplication" function then the program throws the error. I feel like I must be doing something wrong. But if so, I can't see what it is. If you would take a look at this, that would be great. Thanks, Zachary |
From: Duke N. <sid...@gm...> - 2021-11-13 14:23:49
|
This is my first ever Seed7 program! I can't seem to find the bug in the code. Line 30 I think is the problem, but why? *** Uncaught exception RANGE_ERROR raised with {raise RANGE_ERROR } Stack: in raise (ref EXCEPTION: anException) at /home/dnormandin/git/seed7/s(323) in (attr ) (ref : ) at (463) in (inout : , inout : ) at (102) in (inout : ) at (170) in at (31) Process s7 exited with code 0 [code] $ include "seed7_05.s7i"; $ include "complex.s7i"; $ include "char.s7i"; $ include "console.s7i"; const func float: fahr2cels (in float: temp) is return 0.5556 * (temp - 32.0); const func float: cels2fahr (in float: temp) is return (temp * 1.8) + 32.0; const proc: main is func local var float: temp is 0.0; var char: choice is ' '; var text: console is STD_NULL; begin console := open(CONSOLE); clear(console); while choice <> 'q' do writeln("\nTemperature Conversion Utility"); writeln("------------------------------"); writeln("a - Fahrenheit TO Celsius"); writeln("b - Celsius TO Fahrenheit"); writeln("q - To exit the program"); write("Enter your choice "); readln(choice); case choice of when {'a'}: write("Enter a number to convert "); readln(temp); writeln("\nYour input was " <& temp <& " degrees Fahrenheit!"); write("That's " <& fahr2cels(temp) <& " degrees Celsius!"); write("\nPress any key to continue .."); readln; clear(console); when {'b'}: write("Enter a number to convert "); readln(temp); writeln("Your input was " <& temp <& " degrees Fahrenheit!"); write("That's " <& cels2fahr(temp) <& " degrees Celsius!"); writeln("\nPress any key to continue .."); readln; clear(console); when {'q'}: writeln("Good bye!"); writeln("\nPress any key to continue .."); readln; otherwise: writeln("Sorry! Invalid choice!"); writeln("\nPress any key to continue .."); readln; clear(console); end case; end while; end func; [/code] -- Duke Normandin <sid...@gm...> |
From: Duke N. <sid...@gm...> - 2021-11-12 20:28:10
|
On Fri, 12 Nov 2021 21:20:17 +0100 Thomas Mertes <tho...@gm...> wrote: > There are two things that use the keyword 'func'. > > 1. There are types like 'func integer' or 'func boolean'. > 2. There is the 'func ... begin ... end func' construct. [snip the rest of the Good Stuff] > I hope this helps. Thanks! I'm sure that it will once I digest the different nuances. -- Duke |
From: Thomas M. <tho...@gm...> - 2021-11-12 20:20:25
|
There are two things that use the keyword 'func'. 1. There are types like 'func integer' or 'func boolean'. 2. There is the 'func ... begin ... end func' construct. The type 'proc' is defined as 'func void'. The type 'void' describes that there is no value. In fact 'void' has a value, but there is just one value: 'empty'. So the type 'func void' aka 'proc' means: A function that returns nothing. In Pascal and other languages this is called procedure. In Seed7 the name function refers also to procedures as they are functions that return 'void'. The 'func ... begin ... end func' construct comes in several variants. An example of a procedure declarations is: const proc: main is func begin writeln("hello world"); end func; The 'func ... begin ... end func' construct is used to initialize the 'main' procedure. A variant of this func construct is used to define a procedure with local variables. E.g.: const proc: main is func local var integer: number is 0; begin for number range 10 downto 0 do writeln(number); end for; end func; Functions (that do not return void) are initialized with another variant of the construct: 'func result ... begin ... end func'. const func string: foo is func result var string: stri is ""; begin for 3 do stri &:= rand('a', 'z'); end for; end func; A function with a local variable is: const func string: bar is func result var string: stri is ""; local var integer: number is 0; begin for number range 1 to rand(1, 10) do stri &:= str(number); end for; end func; So 'func begin ...' and 'func local ...' are used to define procedures (aka proc). And 'func result ...' is used to define functions (except func void aka proc). As you figured out the 'func ...' construct is overloaded. There is another way to define a function. This way is used when an expression can describe the function body: const func integer: random10 is return rand(1, 10); I hope this helps. Regards Thomas |
From: Duke N. <sid...@gm...> - 2021-11-12 19:02:18
|
I'm totally confused with Seed7's use of "func". In other languages - pascal, oberon2, modula2 etc - a procedure DOES something, but returns nothing. On the other hand, a function can return a value, and sometimes modify an existing value. Seed7 appears to overload the term "func" to mean: - a function declaration, and - begin ... end or { ... } Is that correct? Are procedures and functions specifically explained somewhere? I could not find it in the manual OR the tutorial. I had to go to rosettacode.org for a simple explanation of a seed7 function construct. However, there was nothing there about how to properly write a seed7 procedure. TIA ... -- Duke Normandin <sid...@gm...> |
From: Duke N. <sid...@gm...> - 2021-11-12 14:27:14
|
On Fri, 12 Nov 2021 09:23:00 +0100 Thomas Mertes <tho...@gm...> wrote: > Hi Duke, > > Welcome to Seed7. > Sorry for the delay. The motherboard of my main computer broke > down and it was necessary to get a replacement. I understand! Thank you for your point-by-point replies! All very helpful. Now that I know that the list is still active, I'll continue learning Seed7. So far, it has been a lot of fun. -- Duke |
From: Thomas M. <tho...@gm...> - 2021-11-12 08:25:54
|
Hi Duke, Welcome to Seed7. Sorry for the delay. The motherboard of my main computer broke down and it was necessary to get a replacement. Regarding editor recommendations: Up to now there is neither an Emacs mode nor a jEdit syntax file for Seed7. The following things might be used as inspiration: Renato Lenzi wrote a wordfile for Ultraedit (see: doc/seed7.uew) and a syntax definition file for Textpad (see: doc/seed7.syn). The script to create the Seed7 Homepage uses the following definitions to do the syntax highliting: keywordList: "begin", "case", "const", "do", "downto", "else", "elsif", "end", "enum", "for", "forward", "func", "if", "in", "include", "inout", "is", "local", "new", "of", "otherwise", "param", "range", "ref", "repeat", "return", "struct", "sub", "syntax", "system", "then", "to", "until", "val", "var", "when", "while" operatorList: "and", "conv", "digits", "div", "exp", "in", "lpad", "lpad0", "mdiv", "mod", "mult", "not", "or", "parse", "rem", "rpad", "sci", "times", "varConv" abstractTypeList: "array", "func", "hash", "set", "varfunc" typeList: "bigInteger", "bigRational", "bitset", "boolean", "char", "clib_file", "color", "complex", "duration", "expr", "file", "float", "integer", "object", "proc", "program", "rational", "reference", "ref_list", "string", "text", "time", "type", "void", "PRIMITIVE_WINDOW" Regarding the jEdit seed7 mode: Great that you created a jEdit syntax highlighting mode for seed7. It would ge great to add your jEdit syntax file to the Seed7 release (if it is licensed as open source). You asked what programming language does resemble the seed7 syntax most. I would suggest Ada, Modula 2, or Pascal. Regarding Function Declarations: Seed7 functions must be declared before they can be used. So functions must be declared before main() or some other function uses them. Yes, there is something similar to prototyping like in C. If it is not possible to declare a function (e.g. two functions calling each other) a function can be declared forward: const proc: syncFile (in string: sourcePath, in string: destPath, in syncFlags: flags) is forward; You can see that the keyword forward is used instead of the function body. After the forward declaration syncFile() can be used by another function (e.g. in the function syncDir): syncFile(sourcePath & "/" & sourceName, destPath & "/" & destName, flags); Of course, later the real declaration of syncFile() needs to be done. Regarding your October posts: Your October post have not been nuked. I was just too busy with other things. Sorry for the inconveniance again. Regards Thomas |
From: Duke N. <sid...@gm...> - 2021-11-11 21:17:43
|
Have they cleared the moderator review yet? Or have they been nuked? -- Duke -- Duke Normandin <sid...@gm...> |
From: Thomas M. <tho...@gm...> - 2021-11-07 13:32:45
|
Hi Anders, Sorry for the delay. The motherboard of my main computer broke down and it was necessary to get a replacement. You wrote: > I have a new question which is about writing to different windows. > To illustrate this I have created a small test program (test9.sd7), > which is appended below. > The program opens a window which is the curr_win window. By pressing > F1 a second window is opened named testWindow. When pressing F1 in > the second window it is supposed to write the string "Test", but > instead of writing it in testWindow it is written in the curr_win > window. This confuses me since when I check the "openPixmapFontFile" > function it sets the specified window (testwindow) as the destination > window. Also I am a bit confused about the write-function for the > pixmap font file. > So my question is how is this working? and How should one do this? You discovered an error in pixmap_file.s7i. Several functions were drawing to curr_win instead of fontFile.win. I just checked in the fix to GitHub (see https://github.com/ThomasMertes/seed7). The next release will contain this fix also. Thank you for reporting the bug. Regards Thomas |
From: Duke N. <sid...@gm...> - 2021-10-11 20:00:34
|
Please - do they need to be "prototyped" like in C? Must they be declared before "main"? TIA ... -- Duke |
From: Duke N. <sid...@gm...> - 2021-10-10 20:00:48
|
Hello ... My jEdit syntax highlighting file for seed7 works - but not so well. What programming language does the seed7 syntax *most* resemble please? Thank you! -- Duke Alberta, Canada -- Duke Normandin <sid...@gm...> |
From: Duke N. <sid...@gm...> - 2021-10-09 03:16:39
|
I just put a not too bad looking syntax highlighting mode for seed7 in the almost awesome jEdit editor. If anyone is using jEdit and is interested, let me know! This list seems awfully quiet! I hope that's not a bad thing!! -- Duke |
From: Duke N. <sid...@gm...> - 2021-10-08 20:32:12
|
Noob to seed7 here! Any emacs major mode hiding somewhere? jEdit syntax file? Trying to set up a comfortable workflow after a successful compile on my Linux antiX (Debian-based) box. Thx -- Duke |
From: Zaakari <Za...@pr...> - 2021-09-20 22:05:51
|
Ah, I see. Well don't sweat too much over it. Either I'll have a complicated directory structure with simple file names, or I'll have complicated file names with a simple directory structure. So, feel free to leave it how it is. Thanks, though, for sharing the ins and outs of how the includes work, Zachary ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Friday, September 17th, 2021 at 1:35 PM, Thomas Mertes <tho...@gm...> wrote: > Hi Zachary, > > Seed7 has a mechanism to avoid that the same library is included twice. > You can see this mechanism at the end of seed7_05.s7i. > A map of file names (not paths) is used to avoid that the same library is included twice. > You have two include files with the name point.s7i (in different directories). > This mechanism skips the second attempt to include point.s7i. > If you name the files different the problem will be gone. > > To solve your problem there must be a map of absolute paths, instead of a map of file names. > It should be the absolute path of the actual include file, not the path from the include statement. > > Possibly, the PRIMITIVE_INCLUDE() function could be changed to return the absolute path of the > actual include. I have to think it over to come to a good solution. > > In the meantime, you can circumvent the problem by giving your include files unique names. > > Regards, > Thomas |
From: Thomas M. <tho...@gm...> - 2021-09-17 22:17:42
|
Hi Sanjay, Regarding 1.: There is no special reason, why PI and E are specified with so many digits. At the time I wrote these definitions I thought, that it looks impressive this way. :-) Regarding 2.: In the latest release (2021-09-04) I added the functions expm1() and log1p() to the math.s7i library. I left the sinh() function as is (it just calls the sinh() function from the C library). I hope that helps. Regards, Thomas |
From: Thomas M. <tho...@gm...> - 2021-09-17 21:58:06
|
Hi Zachary, Seed7 has a mechanism to avoid that the same library is included twice. You can see this mechanism at the end of seed7_05.s7i. A map of file names (not paths) is used to avoid that the same library is included twice. You have two include files with the name point.s7i (in different directories). This mechanism skips the second attempt to include point.s7i. If you name the files different the problem will be gone. To solve your problem there must be a map of absolute paths, instead of a map of file names. It should be the absolute path of the actual include file, not the path from the include statement. Possibly, the PRIMITIVE_INCLUDE() function could be changed to return the absolute path of the actual include. I have to think it over to come to a good solution. In the meantime, you can circumvent the problem by giving your include files unique names. Regards, Thomas |
From: Zaakari <Za...@pr...> - 2021-09-11 16:56:03
|
Hey Thomas, It seems I have stumbled across an error regarding includes. Say my folder structure is like so: - test/ - test.sd7 - code/ - point.s7i - editor_point.s7i Within point.s7i is a structure named "Point", and within editor_point.s7i is a structure named "EditorPoint" which is a sub structure of "Point". Now if test.sd7 includes editor_point.s7i, which in turn includes point.s7i, all is fine. However, if I change my folder structure (and includes) to this: - test/ - test.sd7 - code/ - editor/ - point.s7i - general/ - point.s7i Then the program fails saying it can't find a match for "Point". It doesn't say that it couldn't find the include file "general/point.s7i"; it just seems to skip reading its contents (or something). I'm pretty sure there aren't any other errors, because if I include "general/point.s7i" in test.sd7 then the program works. But that shouldn't be necessary, as it's all ready being included through "editor/point.s7i". I've attached a zip file containing an example program. If you run it, it will crash, but if you un-comment line #2 in test.sd7 (which includes "general/point.s7i"), then it succeeds. So, this error seems to arise when an included file includes another file in different (non-child) directory. If you would take a look at this, I would be grateful. Thanks, Zachary |
From: Thomas M. <tho...@gm...> - 2021-09-07 19:03:42
|
My private Email account was hacked and some mail was sent under my name. Sorry for that. Greetings Thomas |
From: Thomas M. <tho...@gm...> - 2021-09-04 09:04:23
|
Hi Anders, You wrote: > Q1: > Should a local variable in a function always release the memory used for it, > after the function has ended? > Comment: I have seen that an application I have been programming seems to > expand its memory usage every time that a certain function is used. The > function in question is a recursive function and in each recursive call a > copy is taken of a rather large object, using the ::= operator. The object > is passed to the function through the parameter-list and it does not matter > how it is passed (as value or ref call). Regarding Q1: In Q1 you wrote that you are using the ::= operator (statement). The ::= operator should never be called explicit. Internally ::= is used to initialize variables, constants, value parameters and elements of arrays, structs and hashs. But it should never be called explicit. Sorry that the interpreter does not prohibit calling ::= explizit. The compiler does not even generate code for an explicit call of the ::= operator. Basically ::= is like a copy constructor with an additional destination parameter as left operand. There are two main differences between the ::= and the := operator: 1. The ::= operator can also be used to initialize the value of a constant (Calling it explicit totally subverts the concept of a const value). 2. The := operator assumes that the left operand (the destination) already has a legal value (so it might free data of the old value). The ::= operator just overwrites the left operand (the old value is lost and this might result in a memory leak). Nomally ::= is called implicit, when there is no previous legal value (this way there is no memory leak). So I guess that the memory leak from Q1 comes from the explicit use of the ::= operator. > Q2: > Should memory for removed array-elements be released? > Comment: I am using a global array with string elements. This array is used > for passing messages in the application. Each time a message is handled it > is removed from the array. However it seems that a small amount of memory is > leaking due to this. If I deliberately increase message passing the memory > leakage is increased. Regarding Q2: How do you measure the memory usage? There are some mechanisms that hinder the measurement of memory. - The run-time library of Seed7 maintains a cache of string values. The cache allows quick access to new strings without calling malloc(). - If something is appended to a string (with &:= ) more memory is requested than necessary (to avoid calling realloc() too often). - Free and non-free memory in the heap can be intermixed, such that it is not possible to give memory (that has been requested in blocks from the OS) back to the operating system. - On top of that the operating system also does not reclaim memory immediately. Can you create a small test program, that still has this memory leak. With such a test program I can examine what is going on. > Q3: > How do one use the reference-type and the ref_list types? > Comment: My intention here is to use a ref_list variable to store references > to different types objects. But I cannot get this to work.at all. Actually I > get an error even when I try to create a reference to an object. Are there > some good examples I could study? Regarding Q3: The types 'reference' and 'ref_list' are part of the Seed7 reflection API. It is not a reflection in the sense that a program can inspect (or change) its own code. But a program can parse another program and can access all the details of it via the reflection API. The Seed7 compiler works this way. Interpreter and compiler share the same program representation. A 'reference' points to an object in this program representation. In a compiled program the objects of the program representation just don't exist. I am sorry to say: A 'reference' is not intended to be used as some sort of generic pointer. Having a generic pointer that can point anywhere would also be against the philosophy of Seed7. You should consider using OO. You can use object orientation to refer to different stucts (which contain elements with different types). E.g.: -------------------- Start tst275.sd7 -------------------- $ include "seed7_05.s7i"; const type: genericStruct is sub object interface; const proc: doSomething (in genericStruct: aGeneric) is DYNAMIC; const type: structA is new struct var integer: number is 0; end struct; type_implements_interface(structA, genericStruct); const func genericStruct: generateA (in integer: number) is func result var genericStruct: newGenericStruct is structA.value; local var structA: new_structA is structA.value; begin new_structA.number := number; newGenericStruct := toInterface(new_structA); end func; const proc: doSomething (in structA: a) is func begin writeln(a.number); end func; const type: structB is new struct var string: stri is ""; end struct; type_implements_interface(structB, genericStruct); const func genericStruct: generateB (in string: stri) is func result var genericStruct: newGenericStruct is structA.value; local var structB: new_structB is structB.value; begin new_structB.stri := stri; newGenericStruct := toInterface(new_structB); end func; const proc: doSomething (in structB: b) is func begin writeln(b.stri); end func; const proc: main is func local var genericStruct: generic1 is structA.value; var genericStruct: generic2 is structA.value; begin generic1 := generateB("Life, The Universe, and Everything:"); generic2 := generateA(42); write("Answer to the Ultimate Question of "); doSomething(generic1); doSomething(generic2); end func; -------------------- End tst275.sd7 -------------------- As you can see a genericStruct can refer to a struct with an integer or to a struct with a string. A genericStruct is a reference to a struct. The value structA.value is used to initialize a genericStruct, but structA.value is actually never accessed or changed. Using these declarations for some generic reference looks heavy. But if you use OO as general concept the overhead will probably be less. BTW: This could not be done without structs as a struct value carries the information to decide which method should be used at run-time. > Q4: > Is it possible to create proper function pointers? > Comment: I manage to create function pointers to proc-functions without any > parameters. But that is rather pointless. Also in this case it would be > helpful to have some good examples to study. Regarding Q4: Variables and parameters of type 'proc' or 'func aType' are intended to be used to define the parameters of statements. For this purpose they do not need parameters themself. For the function pointers you have in mind this cannot be used (exept for the case without parameters). Originally object orientation has been introduced as a way to have function pointers in a structured way. You should try to refactor your problem to object orientation instead of using function pointers. In Seed7 enumeration types can be combined with object orientation. E.g.: -------------------- Start tst274.sd7 -------------------- $ include "seed7_05.s7i"; const type: testEnum is new enum ONE, TWO, THREE end enum; const proc: test (ONE, in integer: number, in string: stri) is func begin writeln("test(ONE, " <& number <& ", " <& literal(stri) <& ")"); end func; const proc: test (TWO, in integer: number, in string: stri) is func begin writeln("test(TWO, " <& number <& ", " <& literal(stri) <& ")"); end func; const proc: test (THREE, in integer: number, in string: stri) is func begin writeln("test(THREE, " <& number <& ", " <& literal(stri) <& ")"); end func; const proc: test (in testEnum: anEnum, in integer: number, in string: stri) is DYNAMIC; const proc: main is func local var testEnum: enumValue is ONE; begin for enumValue range testEnum do test(enumValue, rand(1, 10), "aTest"); end for; end func; -------------------- End tst274.sd7 -------------------- Keep in mind that using enums with OO is not the only way to use OO. There are plenty ways to do OO without enums. The above example is just near to what is considered as a proper function pointer. I hope this has helped you. If you have more questions, just ask. Regards. Thomas |
From: SJain <zz...@ym...> - 2021-09-01 06:16:18
|
-------- Original Message -------- From: SJain <zz...@ym...> Sent: 30 August 2021 4:35:32 PM IST To: LANG Seed7 <see...@li...> Subject: Seed7 math functions expm1 and lnp1 1. If float accuracy is only double precision (64 bits) why are PI and E specified to so many more digits in math.s7i? 2. There is loss of significant digits of precision when computing a) e^x -1 from exp(x), b) ln(1+x) from ln(x) and c) sinh(x) from exp(x), when x is small, x<<1. This occurs because for x<<1, e^x is close to 1 and e^x -1 is taking difference of two almost equal numbers which are both near unity while the difference is much less than unity. Likwise ln(1+x) and sinh(x) cannot be accurately computed from ln(x) and exp(x) for x<<1. In x87 FPU, C and ANSI Forth, the functions expm1 and lnp1 (log1p in C math library) are provided for x<<1 which allow accurate computation for entire range of x. It may be noted that given exp, ln, expm1 and lnp1 functions one can compute all the hyperbolic functions and their inverses over the entire range of x. I request that expm1 and lnp1 functions be added to math.s7i library and that definition of sinh(x) be suitably amended for small x. Sanjay Jain Agra, India |
From: SJain <zz...@ym...> - 2021-08-30 11:36:31
|
1. If float accuracy is only double precision (64 bits) why are PI and E specified to so many more digits in math.s7i? 2. There is loss of significant digits of precision when computing a) e^x -1 from exp(x), b) ln(1+x) from ln(x) and c) sinh(x) from exp(x), when x is small, x<<1. This occurs because for x<<1, e^x is close to 1 and e^x -1 is taking difference of two almost equal numbers which are both near unity while the difference is much less than unity. Likwise ln(1+x) and sinh(x) cannot be accurately computed from ln(x) and exp(x) for x<<1. In x87 FPU, C and ANSI Forth, the functions expm1 and lnp1 (log1p in C math library) are provided for x<<1 which allow accurate computation for entire range of x. It may be noted that given exp, ln, expm1 and lnp1 functions one can compute all the hyperbolic functions and their inverses over the entire range of x. I request that expm1 and lnp1 functions be added to math.s7i library and that definition of sinh(x) be suitably amended for small x. Sanjay Jain Agra, India |
From: Thomas M. <tho...@gm...> - 2021-06-30 21:34:30
|
Hi Zachary, The latest release of Seed7 (2021-06-27) defines the function setCursorVisible(). With setCursorVisible() it is possible to define if the mouse curser is visible in a window. Sorry that it took so long to deliver it. I considered also custom pointer styles. I am not sure that colored custom pointers can be supported under Windows and Unix. As I want a portable solution I cannot promise custom pointer styles for now (with my currently limited knowledge about this area). Of cause a custom pointer style cannot provide multiple pointers. For multiple pointers you must draw your pointers yourself. Regards Thomas |
From: Zaakari <Za...@pr...> - 2021-05-29 17:06:58
|
Hey Thomas, I was just wondering if you would be willing to add a couple of functions (or variables) to control whether or not the mouse cursor is visible (rendered) in the program's window. There are two reasons why I ask for this functionality: - Custom pointer styles. As it stands, I cannot change the look of the mouse cursor within a Seed 7 program. But if the mouse could be hidden, then I could make a custom graphic and have it move along with the mouse. - Multiple pointers. In the graphics editor I'm working on, I wish to make a symmetry functionality, such that operations done on the left side of an image are also done on the right side. So I would like to create two pointers to make it clear where the operations will take place in each side of an image. These pointers' movements along the x axis would then be opposite to each other. Having the default pointer visible in this scenario would be rather confusing / annoying. If you would consider implementing this, I would be grateful. Thanks, Zachary |
From: Thomas M. <tho...@gm...> - 2021-04-22 20:04:59
|
Hi Zachary, Sorry for the delay, I was rather busy with graphic formats. You write: > Hey Thomas, > > Unfortunately I am still getting errors. However, this time I modified the > chkflt.sd7 program to output the result of the trunc() and round() operations > I'm not sure why I didn't think of this before. > I've attached the files so you can see for yourself, but it appears that > truncating or rounding 9223372036854775807.0 results in -9223372036854775808. > Which you did mention was a possibility in your last e-mail. > > Does this mean something like > "and trunc(9223372036854775807.0) <> -9223372036854775808" is needed? No, it probably means that MAXIMUM_TRUNC_ARGUMENT has the wrong value. For some reason chkccomp.c does not compute MAXIMUM_TRUNC_ARGUMENT correct on your computer. I created a test program: ========== begin chktrunc.c ========== #include "stdio.h" #include "float.h" #include "version.h" #include "common.h" double maxFltValues[] = { -9223372036854773760.0, -9223372036854774784.0, -9223372036854775808.0, -9223372036854777856.0, 9223372036854773760.0, 9223372036854774784.0, 9223372036854775808.0, 9223372036854777856.0 }; int64Type maxIntValues[] = { -9223372036854773760, -9223372036854774784, -9223372036854775807-1, -1234567890123456789, 9223372036854773760, 9223372036854774784, 9223372036854775807, 1234567890123456789}; int main (int argc, char *argv[]) { int pos; char *outcome[] = {"fail ", "success"}; int64Type minimumTruncArgument; int64Type maximumTruncArgument; for (pos = 0; pos < 8; pos++) { printf("%f: " FMT_D " %s " FMT_D " %f %d %d %d %d\n", maxFltValues[pos], maxIntValues[pos], outcome[(int64Type) maxFltValues[pos] == maxIntValues[pos]], (int64Type) maxFltValues[pos], (double) maxIntValues[pos], maxFltValues[pos] < (double) -9223372036854774784, maxFltValues[pos] > (double) 9223372036854774784, maxFltValues[pos] < (double) -9223372036854775807-1, maxFltValues[pos] > (double) 9223372036854775807); } for (pos = 0; pos < 4; pos++) { if ((int64Type) maxFltValues[pos] == maxIntValues[pos]) { minimumTruncArgument = maxIntValues[pos]; } } for (pos = 4; pos < 8; pos++) { if ((int64Type) maxFltValues[pos] == maxIntValues[pos]) { maximumTruncArgument = maxIntValues[pos]; } } printf("#define MINIMUM_TRUNC_ARGUMENT " FMT_D "\n", minimumTruncArgument); printf("#define MAXIMUM_TRUNC_ARGUMENT " FMT_D "\n", maximumTruncArgument); return 0; } ========== end chktrunc.c ========== This program includes version.h and common.h. You can it compile and run with: gcc chktrunc.c -o chktrunc ./chktrunc On my computer this results in: -9223372036854773760.000000: -9223372036854773760 success -9223372036854773760 -9223372036854773760.000000 0 0 0 0 -9223372036854774784.000000: -9223372036854774784 success -9223372036854774784 -9223372036854774784.000000 0 0 0 0 -9223372036854775808.000000: -9223372036854775808 success -9223372036854775808 -9223372036854775808.000000 1 0 0 0 -9223372036854777856.000000: -1234567890123456789 fail -9223372036854775808 -1234567890123456768.000000 1 0 1 0 9223372036854773760.000000: 9223372036854773760 success 9223372036854773760 9223372036854773760.000000 0 0 0 0 9223372036854774784.000000: 9223372036854774784 success 9223372036854774784 9223372036854774784.000000 0 0 0 0 9223372036854775808.000000: 9223372036854775807 fail -9223372036854775808 9223372036854775808.000000 0 1 0 0 9223372036854777856.000000: 1234567890123456789 fail -9223372036854775808 1234567890123456768.000000 0 1 0 1 #define MINIMUM_TRUNC_ARGUMENT -9223372036854775808 #define MAXIMUM_TRUNC_ARGUMENT 9223372036854774784 Part of chktrunc.c is code that I use in an improved chkccomp.c. Please run it on your computer and tell me the results. Regards Thomas |
From: Thomas M. <tho...@gm...> - 2021-03-21 08:31:26
|
Hi Zachary, Many thanks for your testing and your description of the chkflt.sd7 problems. You wrote: > Hey Thomas, > > It seems I'm still getting this error in version 2021-02-23. I've attached > all the relevant files again. > > I'm not sure what the issue is, but I had a look in the file "chkflt.sd7", > and the lines 4495 and 4496 don't make sense to me. If I understand > correctly, it means if truncating "9223372036854775297.0" does not raise a > range error (which it wouldn't, on my system) and truncating > "9223372036854775297.0" does not equal "9223372036854775807", then an error > is raised. However, I fail to see why truncating "9223372036854775297.0" > would ever equal the higher number of "9223372036854775807". As--on my > system with the higher number of "9223372036854775807"--wouldn't truncating > "9223372036854775297.0" equal itself and not the higher number? The problem is that the tests for trunc() and round() in "chkflt.sd7" test two things instead of one: 1. How a float literal is mapped to the IEEE 754 double-precision float. 2. How trunc() respectively round() work. The IEEE 754 double-precision floating-point format cannot represent all numbers used in these tests. The actual numbers that can be represented as IEEE 754 double-precision float are: 9223372036854773760.0 this is: float(bin64(16#43dffffffffffffe)) 9223372036854774784.0 this is: float(bin64(16#43dfffffffffffff)) 9223372036854775808.0 this is: float(bin64(16#43e0000000000000)) 9223372036854777856.0 this is: float(bin64(16#43e0000000000001)) The numbers in between them (such as 9223372036854775297.0) do not exist as IEEE 754 double-precision float. So a literal between these numbers is rounded towards the next existing double-precision float. Tests for trunc() and round() with these in-between numbers depend on how float literals are rounded. These literal rounding is a totally different issue that should not be considered when testing trunc() and round(). I decided to reduce the tests to: trunc( 9223372036854773760.0) <> 9223372036854773760 or trunc( 9223372036854774784.0) <> 9223372036854774784 or not raisesRangeError(trunc( 9223372036854775807.0)) and trunc( 9223372036854775807.0) <> 9223372036854775807 or not raisesRangeError(trunc( 9223372036854777856.0)) or Now only representable IEEE 754 double-precision floating-point values are used. The only thing left is the use of 9223372036854775807.0 instead of 9223372036854775808.0. In this case I am quite sure that the rounding of the float literal chooses 9223372036854775808.0 as IEEE 754 double-precision representation. On your computer the float literal 9223372036854775807.0 is internally represented as 9223372036854775808.0 and trunc() converts it to 9223372036854775807. The test for 9223372036854775807.0 either expects a RANGE_ERROR or the correct value (9223372036854775807). Seed7 uses the C cast functionality to trunc() and round() float values to integers. The C cast is used for performance reasons, because C probably uses a fast solution for the cast. Unfortunately the C cast of a float to an integer does not always work the same. Some C compilers do cast 9223372036854775808.0 to 9223372036854775807 and others return a negative value (-9223372036854775808). Therefore I decided that the Seed7 functions trunc() and round() either return the correct value or raises RANGE_ERROR. The next release will contain the fixed chkflt.sd7. If there are still issues please tell me. Regards Thomas |