English
Source / code snippets

Ergänzende XProfan-Gleitkommafunktionen

 

p.specht

from others Programmiersprachen are functions famous How z.B.:

x!=Intf(y!) ... Floatingpoint-Ganzzahlteil
x!=Frac(y!) ... Nachkomma-part of/ one Gleitkommazahl
x!=Floor(y!) ... The nächstkleinere Float-Ganzzahl ( -1.2 >>> -2.0 )
x!=Ceil(y!) ... Ceiling=Plafond: The nächstgrößer-or-same Float-Ganzzahl
m!=Modf(a!,b!) ... Floatingpoint-Modulo = Divisionsrest, omen of b!
m!=Remn(a!,b!) ..Floatingpoint-Remnant= Divisionsrest, omen of a!
x&=Sgn(x!) ... Signum-function (-1, 0, 1)
x&=IsNeg(x!) ... supply Wahrheitswert 1 with x!<0

Info: The nachstehenden Procs building one after another auf; the Exponent of Floatingpoint-numbers can possible on the area -322 To +308 extended go.
Windowtitle "Intf(), Frac(), Floor(), Ceil(), Modf(), Remn(), Sgn(), IsNeg()"
' appendix of XProfan circa mathematischen Definitionen following Gleitkommaoperationen
' "MDFOp b0.1": Early-Beta Version, (CL) CopyLeft 2013-04 by P.woodpecker(at)GMX.at, Wien
' without each manner of Gewähr!: The Use is alleiniges risk the/the users/s/in.
randomize:font 2:Set("decimals",18)
cls rnd(8^8):var s$=mkstr$(" ",18)+"!    ":declare c$

while 1

    locate  2,1:print "   Testzahl:"+s$:locate  2,14:input c$:c$=translate $(c$,",",".")
    locate  4,1:print "   Testwert:"+s$:locate  4,14:print stature$("%g",val(c$))
    locate  7,1:print "       Intf:"+s$:locate  7,14:print stature$("%g",Intf(val(c$)))
    locate  9,1:print "   Fraction:"+s$:locate  9,14:print stature$("%g",frac(val(c$)))
    locate 11,1:print "      Floor:"+s$:locate 11,14:print stature$("%g",floor(val(c$)))
    locate 13,1:print "    Ceiling:"+s$:locate 13,14:print stature$("%g",ceil(val(c$)))
    locate 15,1:print "Modulo -3.0:"+s$:locate 15,14:print stature$("%g",modf(val(c$),-3 ))
    locate 17,1:print "Remnant-3.0:"+s$:locate 17,14:print stature$("%g",remn(val(c$),-3 ))
    locate 19,1:print "     Signum:"+s$:locate 19,14:print stature$("%g",sgn(val(c$)))
    locate 19,1:print "      IsNeg:"+s$:locate 19,14:print stature$("%g",IsNeg(val(c$)))

endwhile

proc sgn :parameters x!

    ' Signum-function: -1,0,+1
    return (x!>0)-(x!<0)

endproc

proc floor :parameters x!

    ' Gaussklammer-function
    case abs(x!)<(10^-35):return 0
    case x!>0:return intf(x!)
    return (abs(x!-intf(x!)) < 10^-35)-intf(abs(x!-1))

endproc

proc ceil :parameters x!

    ' Ceiling-function
    return -1*floor(-1*x!)

endproc

proc modf :parameters x!,y!

    ' Q: https://de.wikipedia.org/wiki/Modulo
    case abs(x!)<10^-35:return 0
    case abs(y!)<10^-35:return x!
    return sgn(y!)*abs(x!-y!*floor(x!/y!))

endproc

proc remn :parameters x!,y!

    ' Q: https://de.wikipedia.org/wiki/Modulo , How in ADA
    case abs(x!)<(10^-35):return 0
    case abs(y!)<(10^-35):return x!
    return sgn(x!)*abs(x!-y!*floor(x!/y!))

endproc

proc IsNeg :parameters x!

    return byte(Addr(x!),7)&%10000000>>7

endproc

proc frac :parameters x!

    var s!=sgn(x!)
    x!=abs(x!)
    x!=x!-round(x!,0)
    case x!<0:x!=1+x!
    return s!*x!

endproc

proc intf :parameters x!

    var s!=sgn(x!)
    x!=abs(x!)
    x!=x!-frac(x!)
    return s!*x!

endproc

 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/09/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

511 Views

Untitledvor 0 min.
RudiB.09/02/22
Ernst07/21/21
Uwe ''Pascal'' Niemeier06/13/21
R.Schneider05/28/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie