...compartiendo esta pagina, que escribí, del WIKI del foro italiano:
http://www.gambas-it.org/wiki/index...eria_quadmath.h
Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Subject: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Last edited by vuott on Saturday, 22 October 2016, 23:23; edited 2 times in total
Last edited by vuott on Saturday, 22 October 2016, 23:23; edited 2 times in total
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Gracias Vuott.
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Last edited by razaAztk on Sunday, 23 October 2016, 04:18; edited 1 time in total
Excelente vuott!!!! Gracias.
Con tu implementación he podido hacer un mayor cálculo de lo que el otra vez se discutió acerca del número ideal de mujeres ( https://foro.gambas-es.org/viewtopic.php?f=8&t=5865#p34874 ). Que con el tipo de dato float de gambas (que son 8 bytes) sólo se podían tener 170 dificultades y ahora son 10 veces más (1755 dificultades).
Con tu implementación he podido hacer un mayor cálculo de lo que el otra vez se discutió acerca del número ideal de mujeres ( https://foro.gambas-es.org/viewtopic.php?f=8&t=5865#p34874 ). Que con el tipo de dato float de gambas (que son 8 bytes) sólo se podían tener 170 dificultades y ahora son 10 veces más (1755 dificultades).
' gambas module file
Library "/tmp/libfloat128q"
' char * Float128q(int dcm, char *num1, char *num2, char *opera)
' La funzione contenuta nella nostra libreria dinamica per la gestione delle risorse della libreria esterna "quadmath.h"
Private Extern Float128q(dcm As Integer, num1 As String, num2 As String, opera As String) As String
Public Const e As Float = 2.7182818285
Public Const pi As Float = 3.1415926535
Public operazione As String[] = ["add", "sot", "mol", "div"]
Public Sub Main()
Dim ver, s As String
Dim n As Integer = 1755 ' 170 '' donde n son el numero de dificultades
Dim y As String '' donde y es el total de mujeres para ti
' Cerca la cartella della versione di gcc contenente il file header "quadmath.h":
ver = Versione()
' Va a creare la nostra apposita libreria dinamica esterna .so per la gestione delle risorse della libreria esterna "quadmath.h":
CrealibFloat128q(ver)
y = Float128q(64, Float128q(64, factorial(n), CStr(Sqr(2 * Pi * n)), operazione[3]), power((n / e), n), operazione[3])
Print "\nNumero máximo de mujeres recomendable: "; Val(y)
End
Private Function Versione() As String
Dim dd As String[]
Dim percorso, d As String
percorso = "/usr/lib/gcc/x86_64-linux-gnu/"
dd = Dir(percorso, Null, gb.Directory).Sort(gb.Descent)
For Each d In dd
If Exist(percorso &/ d &/ "quadmath.h") Then Exit
Next
Return d
End
Private Procedure CrealibFloat128q(v As String)
' Scrive il codice sorgente della nostra apposita libreria dinamica esterna:
File.Save("/tmp/libfloat128q.c", "#include </usr/lib/gcc/x86_64-linux-gnu" &/ v &/ "include/quadmath.h>\n" &
"#include <stdio.h>\n" &
"#include <string.h>" &
"\n\n" &
"char buf[128];" &
"\n\n\n" &
"char * Float128q(int dcm, char *num1, char *num2, char *opera) {" &
"\n\n" &
" char str[4];\n" &
" char dest[16] = \"%+-#*.\";\n" &
" __float128 fl1, fl2, ris;" &
"\n\n\n" &
" sprintf(str, \"%d\", dcm);\n" &
" strcat(dest, str);\n" &
" strcat(dest, \"Qe\");" &
"\n\n" &
" fl1 = strtoflt128(num1, NULL);\n" &
" fl2 = strtoflt128(num2, NULL);" &
"\n\n" &
" if (strcmp(opera, \"add\") == 0 ) {\n" &
" ris = fl1 + fl2;\n }" &
"\n\n" &
" if (strcmp(opera, \"sot\") == 0 ) {\n" &
" ris = fl1 - fl2;\n }" &
"\n\n" &
" if (strcmp(opera, \"mol\") == 0 ) {\n" &
" ris = fl1 * fl2;\n }" &
"\n\n" &
" if (strcmp(opera, \"div\") == 0 ) {\n" &
" ris = fl1 / fl2;\n }" &
"\n\n\n" &
" quadmath_snprintf(buf, 128, dest, ris);"
"\n\n" &
" return buf;\n\n}")
' Genera la nostra apposita libreria dinamica esterna:
Shell "gcc -o /tmp/libfloat128q.so /tmp/libfloat128q.c -shared -fPIC -lquadmath" Wait
End
Public Function factorial(val As Integer) As String
Dim i As Integer
Dim y As String = "1"
For i = 1 To val
'y *= i
y = Float128q(64, y, CStr(i), operazione[2])
Next
Return y
End
Public Function power(x As Float, z As Integer) As String
Dim i As Integer
Dim y As String
Dim yy As String
yy = CStr(x)
y = yy
For i = 2 To z
y = Float128q(64, y, yy, operazione[2])
Next
Return y
End
Library "/tmp/libfloat128q"
' char * Float128q(int dcm, char *num1, char *num2, char *opera)
' La funzione contenuta nella nostra libreria dinamica per la gestione delle risorse della libreria esterna "quadmath.h"
Private Extern Float128q(dcm As Integer, num1 As String, num2 As String, opera As String) As String
Public Const e As Float = 2.7182818285
Public Const pi As Float = 3.1415926535
Public operazione As String[] = ["add", "sot", "mol", "div"]
Public Sub Main()
Dim ver, s As String
Dim n As Integer = 1755 ' 170 '' donde n son el numero de dificultades
Dim y As String '' donde y es el total de mujeres para ti
' Cerca la cartella della versione di gcc contenente il file header "quadmath.h":
ver = Versione()
' Va a creare la nostra apposita libreria dinamica esterna .so per la gestione delle risorse della libreria esterna "quadmath.h":
CrealibFloat128q(ver)
y = Float128q(64, Float128q(64, factorial(n), CStr(Sqr(2 * Pi * n)), operazione[3]), power((n / e), n), operazione[3])
Print "\nNumero máximo de mujeres recomendable: "; Val(y)
End
Private Function Versione() As String
Dim dd As String[]
Dim percorso, d As String
percorso = "/usr/lib/gcc/x86_64-linux-gnu/"
dd = Dir(percorso, Null, gb.Directory).Sort(gb.Descent)
For Each d In dd
If Exist(percorso &/ d &/ "quadmath.h") Then Exit
Next
Return d
End
Private Procedure CrealibFloat128q(v As String)
' Scrive il codice sorgente della nostra apposita libreria dinamica esterna:
File.Save("/tmp/libfloat128q.c", "#include </usr/lib/gcc/x86_64-linux-gnu" &/ v &/ "include/quadmath.h>\n" &
"#include <stdio.h>\n" &
"#include <string.h>" &
"\n\n" &
"char buf[128];" &
"\n\n\n" &
"char * Float128q(int dcm, char *num1, char *num2, char *opera) {" &
"\n\n" &
" char str[4];\n" &
" char dest[16] = \"%+-#*.\";\n" &
" __float128 fl1, fl2, ris;" &
"\n\n\n" &
" sprintf(str, \"%d\", dcm);\n" &
" strcat(dest, str);\n" &
" strcat(dest, \"Qe\");" &
"\n\n" &
" fl1 = strtoflt128(num1, NULL);\n" &
" fl2 = strtoflt128(num2, NULL);" &
"\n\n" &
" if (strcmp(opera, \"add\") == 0 ) {\n" &
" ris = fl1 + fl2;\n }" &
"\n\n" &
" if (strcmp(opera, \"sot\") == 0 ) {\n" &
" ris = fl1 - fl2;\n }" &
"\n\n" &
" if (strcmp(opera, \"mol\") == 0 ) {\n" &
" ris = fl1 * fl2;\n }" &
"\n\n" &
" if (strcmp(opera, \"div\") == 0 ) {\n" &
" ris = fl1 / fl2;\n }" &
"\n\n\n" &
" quadmath_snprintf(buf, 128, dest, ris);"
"\n\n" &
" return buf;\n\n}")
' Genera la nostra apposita libreria dinamica esterna:
Shell "gcc -o /tmp/libfloat128q.so /tmp/libfloat128q.c -shared -fPIC -lquadmath" Wait
End
Public Function factorial(val As Integer) As String
Dim i As Integer
Dim y As String = "1"
For i = 1 To val
'y *= i
y = Float128q(64, y, CStr(i), operazione[2])
Next
Return y
End
Public Function power(x As Float, z As Integer) As String
Dim i As Integer
Dim y As String
Dim yy As String
yy = CStr(x)
y = yy
For i = 2 To z
y = Float128q(64, y, yy, operazione[2])
Next
Return y
End
Last edited by razaAztk on Sunday, 23 October 2016, 04:18; edited 1 time in total
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Os vais acercando, os vais acercando...
razaAztk escribió: [Ver mensaje]
Os vais acercando, os vais acercando...
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Muchísimas gracias, Vuott.
PS.- Efectivamente, nos vamos acercando a... ¡1!
PS.- Efectivamente, nos vamos acercando a... ¡1!
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Es importante - por lo que atañe a los numeros de coma flotante - tener cuidado con el carácter separador de la parte entera y de la parte decimal: se debe usar el carácter "local".
Creo que todos nosotros neo-latinos usamos la coma (exemplum: 123,4567) y no el punto.
Creo que todos nosotros neo-latinos usamos la coma (exemplum: 123,4567) y no el punto.
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Last edited by vuott on Monday, 24 October 2016, 23:57; edited 1 time in total
Os recuerdo que por lo atañe a los numeros enteros es posible usar los recursos del Componente gb.gmp:
http://gambaswiki.org/wiki/comp/gb.gmp
http://gambaswiki.org/wiki/comp/gb.gmp
Last edited by vuott on Monday, 24 October 2016, 23:57; edited 1 time in total
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Subject: Re: Operaciones Con Precisión Cuádruple De 128-bit Con Números En Coma Flotante A Través De La Librería Quadmath.h
Page 1 of 1
You cannot post new topicsYou cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events
This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by Icy Phoenix based on phpBB
Design by DiDiDaDo
Generation Time: 0.2131s (PHP: 17% SQL: 83%)
SQL queries: 26 - Debug Off - GZIP Enabled